Monthly Archive

Categories

Powershell default parameters

The issue Scope issue with Install-Module that I discussed in recent posts is annoying because I know that I’ll forget about it and end up installing in the wrong place and have to uninstall and reinstall. Then I remembered PowerShell default parameters.

 

By adding the line

$PSDefaultParameterValues = @{'Install-Module:Scope'='AllUsers'}

into my PowerShell v6 profile I’ve removed the issue. Install-Module will always default to –Scope AllUsers and if I need to override it I can.

 

$PSDefaultParameterValues is a hashtable where the key is constructed from the cmdlet name and the parameter and a value is supplied.

 

I use the same profile for production and preview PowerShell v6 instances so all should be good – until there’s another change.

Comments are closed.