Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Modify an user attribute using Powershell script

$
0
0

In the current account creation script I am setting the following two attributes targetAddress and proxyAddressess:

$UserAttributes[0].Add('targetAddress', $User.mail)
 $UserAttributes[0].Add('proxyAddresses', "SMTP:" + $User.mail)

I need to be able to change these values sometimes.  I thought if I replaced add with replace that would work it did not.

Ideas?


Here is the whole function:

 $AttributeItems=$UserAttributes[0].GetEnumerator()
 ForEach ($AttributeItem in $AttributeItems) {
  $AIKey=$AttributeItem.Key
  $NewAttribute=$AttributeItem.Value
  $ADAttribute=$FullUser.$AIKey
  if ($ADAttribute -ne $NewAttribute) {
   Set-ADUser $User.sAMAccountName -Replace @{$AIKey=$NewAttribute}
  }
 }
 
 $UserAttributes[0].Add('targetAddress', $User.mail)
 $UserAttributes[0].Add('proxyAddresses', "SMTP:" + $User.mail)
 
 $ClearCount=$UserAttributes[1].Count
 If ($UserAttributes[1].Count -gt 0) {
  Set-ADUser $User.sAMAccountName -Clear $UserAttributes[1]
 }
 $enattendantgodot='Hold on there pardner!'


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>