How to disable PSScriptAnalyzer's PSAvoidUsingCmdletAliases in PowerShell Extension in Visual Studio Code












2















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?



see_screenshot_of_the_problem










share|improve this question

























  • 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
















2















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?



see_screenshot_of_the_problem










share|improve this question

























  • 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














2












2








2


1






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?



see_screenshot_of_the_problem










share|improve this question
















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?



see_screenshot_of_the_problem







powershell visual-studio-code






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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.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



















  • 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

















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










1 Answer
1






active

oldest

votes


















3














There's three ways to do that.



Option 1 - Use the search function




  1. Hit F1 in Visual Studio Code to make the search bar appear

  2. Write >PowerShell: Select PS then choose PowerShell: Select PSScriptAnalyzer Rules

  3. remove the checkmark on PSAvoidUsingCmdletAliases

  4. Click on Confirm


Picture:



enter image description here



Option 2 - completely disable ScriptAnalysis




  1. Click the gear Icon in the bottom left corner in Visual Studio Code

  2. Click on Settings

  3. Click the {} Symbol on the top right corner

  4. Add "powershell.scriptAnalysis.enable": false to your user settings on the right hand side (see screenshot below).

  5. Save your User Settings by hitting CTRL + S


Screenshot:



enter image description here



Your Script Analyzer is now disabled and won't complain about Aliases anymore.



Option 3 - create a settings file and only disable Alias information




  1. Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.

  2. Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.

  3. Add "powershell.scriptAnalysis.settingsPath": "C:\foo\bar\FileName.psd1" and save it


Here's a picture of it:



enter image description here



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')
}





share|improve this answer





















  • 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











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
});


}
});














draft saved

draft discarded


















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









3














There's three ways to do that.



Option 1 - Use the search function




  1. Hit F1 in Visual Studio Code to make the search bar appear

  2. Write >PowerShell: Select PS then choose PowerShell: Select PSScriptAnalyzer Rules

  3. remove the checkmark on PSAvoidUsingCmdletAliases

  4. Click on Confirm


Picture:



enter image description here



Option 2 - completely disable ScriptAnalysis




  1. Click the gear Icon in the bottom left corner in Visual Studio Code

  2. Click on Settings

  3. Click the {} Symbol on the top right corner

  4. Add "powershell.scriptAnalysis.enable": false to your user settings on the right hand side (see screenshot below).

  5. Save your User Settings by hitting CTRL + S


Screenshot:



enter image description here



Your Script Analyzer is now disabled and won't complain about Aliases anymore.



Option 3 - create a settings file and only disable Alias information




  1. Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.

  2. Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.

  3. Add "powershell.scriptAnalysis.settingsPath": "C:\foo\bar\FileName.psd1" and save it


Here's a picture of it:



enter image description here



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')
}





share|improve this answer





















  • 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
















3














There's three ways to do that.



Option 1 - Use the search function




  1. Hit F1 in Visual Studio Code to make the search bar appear

  2. Write >PowerShell: Select PS then choose PowerShell: Select PSScriptAnalyzer Rules

  3. remove the checkmark on PSAvoidUsingCmdletAliases

  4. Click on Confirm


Picture:



enter image description here



Option 2 - completely disable ScriptAnalysis




  1. Click the gear Icon in the bottom left corner in Visual Studio Code

  2. Click on Settings

  3. Click the {} Symbol on the top right corner

  4. Add "powershell.scriptAnalysis.enable": false to your user settings on the right hand side (see screenshot below).

  5. Save your User Settings by hitting CTRL + S


Screenshot:



enter image description here



Your Script Analyzer is now disabled and won't complain about Aliases anymore.



Option 3 - create a settings file and only disable Alias information




  1. Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.

  2. Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.

  3. Add "powershell.scriptAnalysis.settingsPath": "C:\foo\bar\FileName.psd1" and save it


Here's a picture of it:



enter image description here



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')
}





share|improve this answer





















  • 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














3












3








3







There's three ways to do that.



Option 1 - Use the search function




  1. Hit F1 in Visual Studio Code to make the search bar appear

  2. Write >PowerShell: Select PS then choose PowerShell: Select PSScriptAnalyzer Rules

  3. remove the checkmark on PSAvoidUsingCmdletAliases

  4. Click on Confirm


Picture:



enter image description here



Option 2 - completely disable ScriptAnalysis




  1. Click the gear Icon in the bottom left corner in Visual Studio Code

  2. Click on Settings

  3. Click the {} Symbol on the top right corner

  4. Add "powershell.scriptAnalysis.enable": false to your user settings on the right hand side (see screenshot below).

  5. Save your User Settings by hitting CTRL + S


Screenshot:



enter image description here



Your Script Analyzer is now disabled and won't complain about Aliases anymore.



Option 3 - create a settings file and only disable Alias information




  1. Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.

  2. Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.

  3. Add "powershell.scriptAnalysis.settingsPath": "C:\foo\bar\FileName.psd1" and save it


Here's a picture of it:



enter image description here



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')
}





share|improve this answer















There's three ways to do that.



Option 1 - Use the search function




  1. Hit F1 in Visual Studio Code to make the search bar appear

  2. Write >PowerShell: Select PS then choose PowerShell: Select PSScriptAnalyzer Rules

  3. remove the checkmark on PSAvoidUsingCmdletAliases

  4. Click on Confirm


Picture:



enter image description here



Option 2 - completely disable ScriptAnalysis




  1. Click the gear Icon in the bottom left corner in Visual Studio Code

  2. Click on Settings

  3. Click the {} Symbol on the top right corner

  4. Add "powershell.scriptAnalysis.enable": false to your user settings on the right hand side (see screenshot below).

  5. Save your User Settings by hitting CTRL + S


Screenshot:



enter image description here



Your Script Analyzer is now disabled and won't complain about Aliases anymore.



Option 3 - create a settings file and only disable Alias information




  1. Create a .psd1 File on your Filesystem. Copy the template from below into this file and save it.

  2. Go to your UserSettings in VSCode as described in Option 2 point 1 to 3.

  3. Add "powershell.scriptAnalysis.settingsPath": "C:\foo\bar\FileName.psd1" and save it


Here's a picture of it:



enter image description here



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')
}






share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...