Sunday, May 10, 2020

Splatting in PowerShell


Splatting is a method of passing a group  of parameter to a command as unit.
PowerShell associates each value in the collection with a command parameter.
Splatted parameter values are stored in named splatting variables, which look like standard variables, but begin with an At symbol (@) instead of a dollar sign ($).

 The At symbol tells PowerShell that you are passing a collection of values, instead of a single value.
 It Improves the  readability Code.

Here is the way :

$parm = @{
    name = "testuser"
    AccountExpires = "11-05-2020"
    Description ="This is test user,will be deleted soon"
    password = Read-Host "Enter the passoword" -AsSecureString

}
New-LocalUser @parm



No comments:

Post a Comment

Featured post

System-preferred multifactor authentication (MFA)

Popular Posts