Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 17778

PowerTip: Predefine Cmdlet Parameters in Variable

$
0
0

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


Viewing all articles
Browse latest Browse all 17778

Trending Articles