Skip to content
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Excellentpix Excellentpix

Intelligence Redefined

Excellentpix Excellentpix

Intelligence Redefined

  • Green Energy
  • Tech News
  • Gadget
  • Smartphone
  • Laptop
  • PC
  • About Us
    • Advertise Here
    • Contact Us
    • Privacy Policy
    • Sitemap
  • Green Energy
  • Tech News
  • Gadget
  • Smartphone
  • Laptop
  • PC
  • About Us
    • Advertise Here
    • Contact Us
    • Privacy Policy
    • Sitemap
Subscribe
Close

Search

What is PowerShell Splatting? –
Tech News

What is PowerShell Splatting? –

By Maria H. Gray
February 22, 2023 2 Min Read
0

Powershell Splatting

Have you ever worked on a Powershell command that has grown to the point where you pass so many parameters that reading it becomes a mission? For example, if you want to create a new user in AD, you can easily require 10 parameters to perform a basic user setup. For a lot of commands, everything can fit cleanly on one line and within either the standard 80-character width of a standard prompt or the full-screen width of your favourite editor. But sometimes you will want to specify a LOT of parameters, and some of those parameter values may be lengthy in nature. The last thing you want to do is scroll sideways through your code to read and edit it. Powershell Splatting is a technique that offers a convenient way to format and send arguments to cmdlets and functions. Instead of a long list of parameters or those same parameters separated by error-prone backticks, you can leverage splatting to make your code more readable and easier to use.

Below is two examples of code with and without Powershell Splatting

Here is what this would look like on one line without splatting:

New-ADUser -Name "Supertechman" -GivenName "Super" -Surname "Techman" -DisplayName "Test User" -SamAccountName "supertechman" -UserPrincipalName "[email protected]" -AccountPassword (ConvertTo-SecureString "PassW0rd!" -AsPlainText -Force) -Enabled $true -City "Brisbane" -State "QLD" -Department "I.T" -Path "ou=Users, ou=LAB, dc=lab, dc=supertechman, dc=com"

See how this can become hard to read.

Here is what this would look like on one line with splatting:

$params = @
    Name="Supertechman";
    Enabled = $true;
    GivenName="Super";
    Surname="Techman";
    Accountpassword = (ConvertTo-SecureString PassW0rd! -AsPlainText -Force);
    Path = "ou=Users, ou=LAB, dc=lab, dc=supertechman, dc=com";
    ChangePasswordAtLogon = $true;
    SamAccountName="supertechman";
    UserPrincipalName="[email protected]";
    City = 'Brisbane';
    State="QLD";
    Department="I.T";
  

New-ADUser @params

How to Splat?

To splat a set of parameters, you first need to create a hashtable. Basically, all you are doing is creating a bunch of lines containing key/value pairs of each parameter and parameter argument.

Then, once you have the hashtable built, pass that set of parameters to the command using @<hashtable name>.

For example, you can create a hashtable called $Params and then pass that set of parameters defined in the hashtable to the New-ADUser cmdlet as shown above.

Splatting parameters to functions and cmdlets is an extremely useful technique for code readability and functionality. You will find it is easier to manipulate hashtables and add, modify and remove values.

Post navigation

Author

Maria H. Gray

Follow Me
Other Articles
Google sued for false Pixel 4 ads, influencers lied about using the phone
Previous

Google sued for false Pixel 4 ads, influencers lied about using the phone

Next

Traefik, Docker and dnsmasq to simplify container networking

No Comment! Be the first one.

Leave a Reply Cancel reply

You must be logged in to post a comment.

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Archives

Categories

  • Car
  • Entertainment
  • Gadget
  • Games
  • general
  • Green Energy
  • internet marketing
  • IT Solutions
  • Laptop
  • Lifestyle
  • PC
  • Property
  • Real estate
  • SEO
  • Smartphone
  • Software Company
  • Start Up
  • Tech News
  • Technology
  • uncategorized

Recent Posts

  • HIPAA EDI Transactions Explained: 834, 835, 837, 270/271, 276/277, 278 and 820
  • AI-Powered Phishing Is Getting Better: How Staff Training Needs to Change in 2026
  • 10 Best Enterprise GEO / AEO / SEO Agencies to Build Offsite Brand Mentions in 2026
  • Brick House Bonanza: Een Ultieme Steensterke Casino Avontuur
  • How a Review Management System Helps Businesses Build a Stronger Online Reputation

fiver

Fiverr Logo

Tags

Amazon Android announces app Apple Big Black Buy Car coming deals Electric Galaxy game games gaming Google Heres Hunter iPhone laptop Laptops launch Market Microsoft news phone Pro Release Review sale Sales Samsung Series Smartphone software startup startups Stock tech Tesla top Windows Xbox year

PHP 2026

roadwayrevolution
arc-records

BL

excellentpix.com

WhatsApp us