IT Questions and Answers :)

Friday, December 1, 2017

In PowerShell, what is "splatting"?

Which of the following does a DNS MX record provide for a given domain?

  • The name of the inbound email server for that domain
  • The web server details of the domain
  • Outgoing email server for the domain
  • Microsoft Exchange related information for the domain 

 
In PowerShell, what is "splatting"?

EXPLANATION

When you have multiple parameters to give to a single cmdlet, you can use a "splat", also known as "splatting".  This is where you build a hash table where each key is a parameter name, and each key's value is the value that you will pass to that parameter.  Once created, you can pass the entire hash table to the cmdlet by calling it with @ instead of $.
Example:
$ADUserSplat = @{
    Department = "IT Department";
    Description = "Person in IT";
    City = "Awesometown";
}

Set-ADUser -Identity ituser @ADUserSplat
Since the splat is actually a hash table, it can be modified, added to, and removed from as a hash table, allowing more programmatic (logic based) constructions of commands, such as "only change the department if they're in one of these three groups", without having to have multiple calls to the same cmdlet in a complex if/elseif/else chain.
Share:

0 comments:

Post a Comment

Popular Posts