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?
powershell visual-studio-code
add a comment |
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?
powershell visual-studio-code
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
@postanote I know why this is done but I will never ever use e.gForeach-Object
orSelect-Object
orGet-ChildItem
in my scripts, no matter what the best practises are.
– SimonS
Jan 14 at 6:44
add a comment |
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?
powershell 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?
powershell visual-studio-code
powershell visual-studio-code
edited Jan 11 at 14:46
TDK
33313
33313
asked Jan 11 at 14:35
SimonSSimonS
2,75731023
2,75731023
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
@postanote I know why this is done but I will never ever use e.gForeach-Object
orSelect-Object
orGet-ChildItem
in my scripts, no matter what the best practises are.
– SimonS
Jan 14 at 6:44
add a comment |
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
@postanote I know why this is done but I will never ever use e.gForeach-Object
orSelect-Object
orGet-ChildItem
in my scripts, no matter what the best practises are.
– SimonS
Jan 14 at 6:44
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
@postanote I know why this is done but I will never ever use e.g
Foreach-Object
or Select-Object
or Get-ChildItem
in my scripts, no matter what the best practises are.– SimonS
Jan 14 at 6:44
@postanote I know why this is done but I will never ever use e.g
Foreach-Object
or Select-Object
or Get-ChildItem
in my scripts, no matter what the best practises are.– SimonS
Jan 14 at 6:44
add a comment |
1 Answer
1
active
oldest
votes
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')
}
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393186%2fhow-to-disable-psscriptanalyzers-psavoidusingcmdletaliases-in-powershell-extens%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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')
}
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
add a comment |
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')
}
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
add a comment |
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')
}
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')
}
edited Jan 14 at 10:41
answered Jan 11 at 14:35
SimonSSimonS
2,75731023
2,75731023
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
add a comment |
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
1
1
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
Thank you for sharing this, Simon.
– root
Jan 11 at 14:37
1
1
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
@root you're welcome. I'm extremely excited about Visual Studio Code! This is a great alternative to PowerShell ISE.
– SimonS
Jan 11 at 14:39
1
1
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
Same here. I have some qualms with VSC, though I think they're due to my lack of understanding of its rich feature set and configurabilty.
– root
Jan 11 at 15:06
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393186%2fhow-to-disable-psscriptanalyzers-psavoidusingcmdletaliases-in-powershell-extens%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This is done because the best practice is not to use aliases in product scripts. powertheshell.com/bp_script_alias It makes them hard to read, hard to maintain and prone to error. Aliases is really targeted for interactive command line stuff. Sure you can use aliases in VSCode as you develop, yet, they really should be replaced before going to production. Use the expand alias command - blogs.technet.microsoft.com/heyscriptingguy/2017/01/12/…
– postanote
Jan 11 at 18:53
@postanote I know why this is done but I will never ever use e.g
Foreach-Object
orSelect-Object
orGet-ChildItem
in my scripts, no matter what the best practises are.– SimonS
Jan 14 at 6:44