If you review the help for Set-ADUser you’ll see that the parameter is named “-EmailAddress”.
BTW: When you have the sAMAccountName in your csv file you don’t need to get the account with Get-ADUser first. You can use right away Set-ADUser with the parameter -Identity wich takes the sAMAccountName.
The -Replace parameter takes a hashtable of one or more values to replace. If you want to set values individually, use other parameters. To replace a bunch at once, use -Replace. Not all AD properties have explicit parameters laid out for you to use with the cmdlet. It is mostly for those that the -Add, -Remove, and -Replace parameters exist; to update those parameters that aren’t accessible through other parameters.
It’ll still work for regular ones, though, and it’s a bit neater than specifying every parameter.
Set-ADUser : The specified directory service attribute or value does not exist
Parameter name: EmailAddress
…yet, I have verified with Get-ADUser that the samAccountName for each in my csv exists.
Does it matter that a current value exists in AD for any given samAccountName? It doesn’t matter that this would get replaced by my values in the .csv.
Lemme see… Okay, the issue is probably that the property names differ slightly depending on your method. Try applying the email using ‘mail’ as the property name instead. (Or just pull that one out of the hashtable and apply it with the -EmailAddress parameter instead.
You are also over complicating things with having to worry about substrings, I would simplify it a bit. In your CSV I would have a column with samaccountname, mail, manager etc then…
I feel like I am getting close to this and the help file for Set-ADUser wasn’t helping completely. It doesn’t address the use of quotes when using the -Replace Parameter. When i used them, I was able to write values without error.
…and it does write to the intended attribute (otherMailbox) but it isn’t just the mail address I want from my .csv. It’s many different things depending on how I arrange the quotes.
I’ve tried the following:
$mgr.“PrimaryContact” ERROR: Set-ADUser : replace At line:2 char:5…)
“‘$mgr’.PrimaryContact” SUCCES WRITE but {‘@{sAMAccountName=svcacctjfw; PrimaryContact=}’.PrimaryContact}
$mgr.PrimaryContact ERROR: Set-ADUser : replace At line:2 char:5…)
…before throwing my hands up in the air!
I just want the next string (mgr.PrimaryContact) in the pipeline (that I verified exists) to populate the otherMailbox attribute.
You’re very close. Your last issue there is that single quotes do not expand variables in strings, period. In this instance, you could simply drop all quotes from the expression. Or, you can use double quotes (but you’d need to be careful because of how PS handles variable properties in strings – it doesn’t, essentially). Or you could use a format string. So… options: