-
Notifications
You must be signed in to change notification settings - Fork 395
Running PSScriptAnalyzer on nanoserver #984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for reporting this. By looking at your referenced document, I do not think/hope that you need to compile PSSA yourself but the instructions say so. Can you also print the output of $PSVersionTable please? If I remember correctly, then NanoServer has a custom version 6 of Windows PowerShell in it. I know there is custom code in PSSA for Windows PowerShell vs PowerShell Core and I imagine it thinks it is a core version because of the 6 in the version and then calls the wrong api... Out of interest: Are you using PSSA in NanoServer as part of testing phase of your CI process or is there a different reason why you need to use it on NanoServer? |
No hurry at all... I'm going to use PSScriptAnalyzer to run Appveyor tests for a package I'm developing.
Sure! Here it is: C:\>docker run --rm --tty microsoft/nanoserver powershell.exe $PSVersionTable
Name Value
---- -----
PSRemotingProtocolVersion 2.3
BuildVersion 10.0.14393.1000
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PSEdition Core
CLRVersion
PSVersion 5.1.14393.1000
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} |
PS:
|
Thanks. Aha, the PSVersionTable reveals that it is actually a (custom pre-release) version of PowerShell Core but of version 5.1 (really confusing versioning but I guess the PowerShell team was asked to quickly give out something that works on NanoServer..). |
P.S. For the moment, I am not sure if PSSA is currently supported or supposed to work on NanoServer as-is since your referenced branch seems to be rather an old PoC. But anyway, I will try to make it work on it. |
Thank you, Christoph. For the time being I just excluded PSSA from my tests on nanoserver (see https://ci.appveyor.com/project/mlocati/powershell-phpmanager/build/Build%2097 ). |
Some minor updates, I can repro now (even when I use
This is happening here because it seems that the docker run --rm --tty microsoft/windowsservercore powershell "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null; Install-Module PSScriptAnalyzer -Force; Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }; Set-Content -Value 'Write-Output ''test''' -Path test.ps1; Invoke-ScriptAnalyzer -Path test.ps1" Or alternatively in Linux mode the powershell image works as well: docker run --rm --tty microsoft/powershell pwsh -c "Install-Module PSScriptAnalyzer -Force; Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }; Set-Content -Value 'Write-Output ''test''' -Path test.ps1; Invoke-ScriptAnalyzer -Path test.ps1" |
Not for me: the PSGallery package I'm developing is meant to work only on Windows (it's used to install/update/configure PHP on Windows). |
Hmm, ok. For the moment, it seems you can only use it using the |
Note that I found that some of the docs on the PowerShell repo seem to be out of date as well. For example they refer to the |
Thank you Christoph, BTW I didn't file this issue for my own needs: in my repo I'm testing two different environments, one being a standard Windows server image, the other being a nanoserver docker image. I filed this issue for the sake of completeness of this great PSSA (it should run on as many platform as possible), for other developers, and for myself if in future I'll write some code that will be tested only on nanoserver. |
@TravisEz13 had deprioritized getting a new image of nanoserver+PSCore6 out since we're in process of rebuilding our docker image creation |
@mlocati Instead of installing it, I just download the module and import it then. You will see a warning message ( docker run -it microsoft/powershell:nanoserver pwsh -c "Save-Module -Name PSScriptAnalyzer -Path .; Import-Module C:\PSScriptAnalyzer; Invoke-ScriptAnalyzer -ScriptDefinition 'gci'" This Docker image contains the 1709 Windows build (10.0.16299) and PowerShell Core 6.0.2 |
@bergmeister Thanks for the deep analysis. BTW I'll continue using microsoft/nanoserver because:
|
@bergmeister Our image is based on |
Uh oh!
There was an error while loading. Please reload this page.
PSScriptAnalyzer does not currently run on nanoserver.
Try this command on a Windows machine with Docker installed (and configured to run Windows containers):
docker run --rm --tty microsoft/nanoserver powershell.exe "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null; Install-Module PSScriptAnalyzer -Force; Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }; Set-Content -Value 'Write-Output ''test''' -Path test.ps1; Invoke-ScriptAnalyzer -Path test.ps1"
The output will be
The only relevant info I found about running PSScriptAnalyzer on NanoServer is located at https://github.com/PowerShell/PSScriptAnalyzer/blob/NanoServer/ExtraStepsSettingUpNanoServerScriptAnalyzer.md , but it seems quite outdated and unmaintained.
The text was updated successfully, but these errors were encountered: