Friday, December 13, 2024
HomePowershell(Parameter) Splatting defined – SID-500.COM

(Parameter) Splatting defined – SID-500.COM


PowerShell

It usually occurs that you’ve got many, many parameters in PowerShell. The command then extends over a number of traces. That doesn’t look fairly. On this article, I’ll present you easy methods to summarize these parameters after which use them within the command. Let’s get began.

Outline Hash Desk with Parameter Names and Values

Let’s summarize these parameters in a hash desk.

$params = @{
    Parameter1 = "Value1"
    Parameter2 = "Value2"
    Parameter3 = "Value3"
}

Subsequent, we name the command by utilizing our hash desk which incorporates all of the parameters and their values.

That’s it. Mission accomplished.

However wait, let me present you one other instance which is extra from the actual phrase, additionally referred to as a real-world-scenario. The code under creates a brand new Energetic Listing person utilizing splatting.

$hash=@{

GivenName="Florian"
Surname="Perfekt"
Title="Florian Perfekt"
Enabled = $true
AccountPassword = (ConvertTo-SecureString -AsPlainText '123user!' -Drive)
DisplayName="Florian Perfekt"
UserPrincipalName="florian.perfekt@pagr.loc"
Path="OU=Benutzer,DC=pagr,DC=loc"

}

New-ADUser @hash

Hope this was useful.

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2025], IT-Coach, IT-Guide, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments