Command line too long..

Hi all,

Just wondering what technique I could use to shorten my command line other than using variables for each parameter…

e.g.
Set-QADUser -Identity $.“Name” -UserPrincipalName $.“UserPrincipalName” -alias $.“alias” -Displayname $.“Displayname” -FirstName $.“FirstName” -LastName $.“LastName” -OrganizationalUnit $.“OrganizationalUnit” -PrimarySmtpAddress $.“PrimarySmtpAddress” -SamAccountName $.“SamAccountName” -Password (ConvertTo-SecureString $.password -AsPlainText -Force)

Any ideas appreciated!

Cheers,
AKP

I prefer to use splatting to keep that sort of long command readable:

$params = @{
    Identity           = $_.Name
    UserPrincipalName  = $_.UserPrincipalName
    Alias              = $_.Alias
    DisplayName        = $_.DisplayName
    FirstName          = $_.FirstName
    LastName           = $_.LastName
    OrganizationalUnit = $_.OrganizationalUnit
    PrimarySmtpAddress = $_.PrimarySmtpAddress
    SamAccountName     = $_.SamAccountName
    Password           = ConvertTo-SecureString $_.Password -AsPlainText -Force
}

Set-QADUser @params

Thanks Dave, just what I was looking for…

Are these hash tables?

Yep, $params is a hash table. When you splat a hashtable, its keys become the names of command Parameters, and its values are the arguments passed to those parameters.

You can also do splatting with an array, in which case each element of the array is passed as a positional parameter, in the same order as the array.

Thank you Dave.
I will do some reading up on arrays as well.

I know understand spaltting!