I have 2 custom attributes called saConcurID and another saSkillportid and I want saConcurID = saSkillportid and this is what I have but it doesn’t like it. Set-ADUser : A parameter cannot be found that matches parameter name ‘Idenity’.
Import-Module ActiveDirectory - ErrorAction stop
$users = Get-ADUser -SearchBase “OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com” -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid
foreach ($user in $users) {
Set-ADUser -Idenity $user -Replace @{saconcurid = "$($_.saskillportid)"}
}
Typo! Idenity should be Identity. You can also us the pipeline to pass in the user.
$user | Set-ADUser -Replace @{saconcurid = $user.saskillportid}
it was only a typo here I typed it correct in my script but I will try your suggestion, thanks
I just tried that and get set-ADUser : Object reference not set to an instance of an object
Hi,
I’m not verifying your script more than fix the $users statement.
$users = Get-ADUser -SearchBase “OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com” -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid
to
$users = Get-ADUser -SearchBase “OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com” -filter * -properties cn, saconcurid, saskillportid
Your select-object kills the ad-object object type. Old school mistake which I run from time to time when getting only the output I want, just to see that it kills the script.
If there’s a performance concern (one reason to trim output, if you’re dealing with a large number of users), you could leave the select statement, but add “samaccountname”. Then, specify the samaccountname property for your identity:
$users = Get-ADUser -SearchBase "OU=blah,OU=blah,OU=blah,DC=blah,DC=blah,DC=com" -filter * -properties cn, saconcurid, saskillportid| Select-Object cn, saconcurid, saskillportid, samaccountname
foreach ($user in $users) {
Set-ADUser -Idenity $user.samaccountname -Replace @{saconcurid = "$($_.saskillportid)"}
}
Either way works; if there isn’t a performance issue you’re trying to overcome, though, I’d just leave Select-Object out. Get-ADUser already returns a limited set of properties by default.