PowerTip: Predefine Cmdlet Parameters in Variable

Doctor Scripto

Dr Scripto

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.”

Doctor Scripto
Dr Scripto

Scripter, PowerShell, vbScript, BAT, CMD

Follow Dr Scripto   

0 comments

    Leave a comment