Powershell Tip #3: Change default parameter values ($PSDefaultParameterValues)

By | July 9, 2015

Tip: You can set some default values for parameters by using the automatic variable $PSDefaultParameterValues.

This preference variable is a hashtable and have some methods such as : Add, Clear, GetEnumerator, Remove, …

psdefaultparametervalues-get-member

For example:

– if you want to have by default -Count 1 and -Quiet $true for Test-Connection.
– if you want to set a default server for Get-AD* cmdlets

psdefaultparametervalues

Note: This change will be permanent only for this session but if you want to have these settings automatically defined everytime you open a new session, you can set them in your PowerShell profile. If you work with Powershell ISE, a quick way to do that:  ise $profile

MSDN:
DefaultParameterDictionary Class


previous-buttonnext-button

Leave a Reply

Your email address will not be published. Required fields are marked *