Home > Net >  ADUser Attributes
ADUser Attributes

Time:11-03

Is there another easier way to set-aduser attributes?

$User = "Please enter a username"
$streetAddress = "555 south"
$city = "New York"
$state = "US"
$postalCode = "55555"
$country = "United States"


Set-aduser -identity $User -Replace @{streetAddress=$streetAddress}
Set-aduser -identity $User -Replace @{l=$city}
Set-aduser -identity $User -Replace @{st=$state}
Set-aduser -identity $User -Replace @{postalCode=$postalCode}
Set-aduser -identity $User -Replace @{co=$country}

CodePudding user response:

The two easier alternatives, both using Splatting.

This is the easiest by far, in this case Set-ADUser gives us friendly Parameter Names and facilitates the translation to their LDAP Display Name behind the scenes. For the AD Attributes being used in the question, luckily, all are available:

$params = @{
    Identity      = "the user here"
    City          = "New York"
    StreetAddress = "555 south"
    State         = "US"
    PostalCode    = "55555"
    Country       = "United States"
}

Set-ADUser @params

This one is doing the exact same thing however here we are actually using the attributes LDAP Display Name ourselves in the replacement hash:

$params = @{
    Identity = "the user here"
    Replace  = @{
        l  = "New York"
        co = "United States"
        st = "US"
        postalCode    = "55555"
        streetAddress = "555 south"
    }
}

Set-ADUser @params
  • Related