January 11th, 2014

PowerTip: Predefine Cmdlet Parameters in Variable

Doctor Scripto
Scripter

Summary: Pass a cluster of parameter values by using an array.

Hey, Scripting Guy! Question Is there an easy way to write Windows PowerShell commands to handle two separate domains
          (for example, production and development) and their credentials?

Hey, Scripting Guy! Answer Define them in an array that contains the parameter names and their values. For example, to pass
          the IP address of a domain controller and credentials as a single variable to the Get-ADUser cmdlet:

$DC=”192.168.1.5”

$Cred=(GET-CREDENTIAL)

$CommonParameters=@{‘Server’=$DC;’Credential’=$Cred)

GET-ADUSER –filter * @CommonParameters

Note If you ask a Windows PowerShell person, the popular term for this is “splatting.”

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.