If you’re an avid user of PowerShell you’ve probably, at some point gotten sick of providing values for the same parameters over and over. The solution, use $PSDefaultParameters. Using this preference variable you can set default values like the DC used with the AD cmdlets, the SQL server you connect to, or the error preference for all cmdlets or a subset. This means you can essentially pre-enter the desired value once, and the cmdlet will automatically use it. Pretty cool, huh?
Examples:$PSDefaultParameterValues["*-AD*:Server"] = "dc01.corp.viamonstra.com"
Add/Remove single entries:$PSDefaultParameterValues.Add('Get-ADComputer:Server', 'dc01')
$PSDefaultParameterValues.Remove('*-GPO:Name')
The $PSDefaultParameterValues variable is only available in the session you set it in. The easiest way to take advantage of $PSDefaultParameterValues is to add them to you PowerShell profile. That way each time you start a PowerShell session, the default values are already set for you.
PowerShell profile example:$PSDefaultParameterValues['Get-ChildItem:Force'] = $true
$PSDefaultParameterValues[':ErrorAction'] = 'Stop' $PSDefaultParameterValues['Get-:Recurse'] = $true
Here is a link to Microsoft’s documentation of $PSDefaultParameters.