SAM2009
asked on
How to set a value in extensionAttribute AD attribute by PowerShell?
Hi,
I have a list of samaccount with their extensionAttribute values in a csv file.
I want to create a Powershell script which checks AD attribute "extensionAttribute2" of each user and add his corresponding extensionAttribute values.
My problem is with extensionAttribute we need to play with ADD, Remove, Clear, Replace parameters and that mixe me up.
If just want to add if there is no value and if there is a value then replace it. But why there is remove and clear parameter?
Is someone can help me for that?
Thanks
I have a list of samaccount with their extensionAttribute values in a csv file.
I want to create a Powershell script which checks AD attribute "extensionAttribute2" of each user and add his corresponding extensionAttribute values.
My problem is with extensionAttribute we need to play with ADD, Remove, Clear, Replace parameters and that mixe me up.
If just want to add if there is no value and if there is a value then replace it. But why there is remove and clear parameter?
Is someone can help me for that?
Thanks
ASKER
But why don't we use also "ADD" parameter? If there is no value we need to use ADD first no?
No. It's the same as with -Remove: you need to use -Add if you want to add more values to an already existing array of values for an attribute.
The attribute itself is always there.
The attribute itself is always there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Which comparison operator can I use to verify if the extensionAttribute is empty or not?
if (user.extensionAttribute -ne " " )
or
if (!user.extensionAttribute)
if (user.extensionAttribute -ne " " )
or
if (!user.extensionAttribute)
The first one will compare against an empty string.If the attribute is cleared, it will be $Null.
So use either
So use either
if ($user.extensionAttribute) {
# Not empty
} Else {
# Empty
}
Or this:if ([string]::IsNullOrEmpty($user.extensionAttribute)) {
# Empty
} Else {
# Not empty
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The reason why I asked that is because I want to update extensionAttribute in user AD from an csv file at every 30 min. So just I'm just wondering if it worth to verify if the value is different first before replacing it or just replace even if the value is the same. Maybe by skiping user that having their extensionAttribute not changed can safe time. What do you think?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help!
Open in new window
Remember that there are attributes that hold arrays. -Remove will remove (only) the values listed in the argument, and Clear will clear all contents of the attribute.