PowerShell / PSScriptAnalyzer

Download ScriptAnalyzer from PowerShellGallery
https://www.powershellgallery.com/packages/PSScriptAnalyzer/
MIT License
1.8k stars 366 forks source link

Missing approved verbs #1961

Closed billprew closed 5 months ago

billprew commented 5 months ago

Before submitting a bug report:

Steps to reproduce

When editing code in VSCode Editor, two verbs that show in the web approved verb list at https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-5.1 are showing in the editor as unapproved (underlined). The two verbs I have noticed are both from the Lifecycle group:


Expected behavior
-----------------
These two verbs should be added and supported as approved.
```none

Actual behavior

These two verbs are flagged as not approved.

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3930
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3930
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.21.0
bergmeister commented 5 months ago

The tool fetches the list of approved verbs here from the used PowerShell instance directly, which is equivalent to running Get-Verb. Since those verbs were only added after PowerShell version 6, they are flagged when you are using the tool in Windows PowerShell. If you install PowerShell 7, VS-Code should start use it automatically and then it will not flag those verbs any more.

billprew commented 5 months ago

Not an issue in PSScriptAnalyzer, rather an issue with the older v5.1 of Windows PowerShell which did not retroactively add the Build and Deploy verbs to the Get-Verb command when they were added to the list in v6+. I imagine it is unlikely that v5 will get these added in the future since it is not being heavily updated going forward.

The suggestion of installing v7 does resolve the problem, but I still am doing a lot of v5 script development / maintenance, so that doesn't really help me. I don't want to make v7 my default in VSC since there are other syntax differences to v5. so I will just live with these two verbs being highlighted as unapproved for now, not a big deal.

bergmeister commented 5 months ago

5.1 only receives critical security fixes. Theoretically we could retrospectively add them in PSSA but it would make things inconsistent because the output of get-verb won't change for 5.1 and as you rightly say so the behaviour of PSSA is aligned to the used PS version. Therefore in the same way how you wouldn't want to mix 5 and 7, someone else wouldn't want v7 verbs when using pssa in v5 even if it's with the best intentions. You can suppress verb specially though, meaning you can still use the rule in a meaningful way