Skip to content

Running PSScriptAnalyzer on nanoserver #984

Closed
@mlocati

Description

@mlocati

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

    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.16.1     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}
Invoke-ScriptAnalyzer : Could not load type 'System.Management.Automation.SemanticVersion' from assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
At line:1 char:257
+ ... Output ''test''' -Path test.ps1; Invoke-ScriptAnalyzer -Path test.ps1
+                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-ScriptAnalyzer], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions