How to disable PSScriptAnalyzer's PSAvoidUsingCmdletAliases in PowerShell Extension in Visual Studio Code
I'm using Visual Studio Code to write my PowerShell Scripts.
I've installed the ms-vscode.powershell
PowerShell Extension for Visual Studio Code.
Whenever I use an Alias in my Script, the PSScriptAnalyzer
tells me to use the full CmdLet Name. This is kind of annoying because it also marks all aliases with a green curvy line.
How can I disable this?
Solution 1:
There's three ways to do that.
Option 1 - Use the search function
- Hit F1 in Visual Studio Code to make the search bar appear
- Write
>PowerShell: Select PS
then choosePowerShell: Select PSScriptAnalyzer Rules
- remove the checkmark on
PSAvoidUsingCmdletAliases
- Click on
Confirm
Picture:
Option 2 - completely disable ScriptAnalysis
- Click the gear Icon in the bottom left corner in Visual Studio Code
- Click on Settings
- Click the
{}
Symbol on the top right corner - Add
"powershell.scriptAnalysis.enable": false
to your user settings on the right hand side (see screenshot below). - Save your User Settings by hitting
CTRL + S
Screenshot:
Your Script Analyzer is now disabled and won't complain about Aliases anymore.
Option 3 - create a settings file and only disable Alias information
- Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.
- Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.
- Add
"powershell.scriptAnalysis.settingsPath": "C:\\foo\\bar\\FileName.psd1"
and save it
Here's a picture of it:
Template (taken from https://github.com/PowerShell/vscode-powershell/blob/develop/examples/PSScriptAnalyzerSettings.psd1):
@{
# Only diagnostic records of the specified severity will be generated.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
# Severity = @('Error','Warning')
# Analyze **only** the following rules. Use IncludeRules when you want
# to invoke only a small subset of the defualt rules.
IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSReservedCmdletChar',
'PSReservedParams',
'PSShouldProcess',
'PSUseApprovedVerbs',
'PSUseDeclaredVarsMoreThanAssigments')
# Do not analyze the following rules. Use ExcludeRules when you have
# commented out the IncludeRules settings above and want to include all
# the default rules except for those you exclude below.
# Note: if a rule is in both IncludeRules and ExcludeRules, the rule
# will be excluded.
ExcludeRules = @('PSAvoidUsingAliases','PSAvoidUsingWriteHost')
}