Author Posts

February 11, 2017 at 3:16 am

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)"}
}

February 11, 2017 at 7:34 am

Typo! Idenity should be Identity. You can also us the pipeline to pass in the user.

$user | Set-ADUser -Replace @{saconcurid = $user.saskillportid}

February 11, 2017 at 2:23 pm

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

February 12, 2017 at 8:56 pm

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.

February 13, 2017 at 3:41 am

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.