Setting default parameter values (Intermediate)

We will learn to set the default parameter values.

Getting ready

$PSDefaultParameterValues is a default preference variable introduced in PowerShell v3.0. This variable sets the custom parameter values to specified CMDLETs and functions. It maintains a hash table to store all of the defined values.

How to do it...

Try the following test code to set the default parameter values:

  1. The following command statement sets the localhost value to the parameter name ComputerName for all CMDLETs that have Invoke as a verb:
    PS C :\> $PSDefaultParameterValues=@{"Invoke-*:ComputerName"="localhost"} 
    

    Tip

    $PSDefaultParameterValues accepts wildcard characters. Also, we can use the ; (semicolon) character to assign multiple ...

Get Instant Windows PowerShell Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.