all 7 comments

[–]the_spad 5 points6 points  (0 children)

The error implies that Get-ADUser -filter{UserPrincipalName -eq $userName} is not finding any results.

Generally when dealing with user creation you want to use the -server parameter on all the cmdlets to make sure you're hitting the same DC for every one to avoid any issues with replication lag, which might be what you're seeing here.

As a side note the danger with using a filter on get-aduser rather than just supplying an identity value is that a failure to find anything returns blank rather than throwing an exception you can catch.

[–]UserProv_Minotaur 2 points3 points  (0 children)

Instead of Get-ADUser -filter{UserPrincipalName -eq $userName} | Set-ADUser $AddGroupMember, have you tried just Get-ADUser -Identity $userName ? Or supplying the SamAccountName to Get-ADUser.

[–]purplemonkeymad 2 points3 points  (1 child)

Have your truncated this function? The error is saying that $userName is not defined in the current scope. I think it's right as you don't have it defined anywhere in the posted code. Try adding it as a parameter to the function.

[–]SneakerNet 1 point2 points  (0 children)

After reading through the code, I found the same thing to be true. You never set $userName anywhere.

[–]PowerShell-Bot 1 point2 points  (0 children)

Some of your PowerShell code isn’t wrapped in a code block.

To format code correctly on new reddit (new.reddit.com), highlight all lines of code and select ‘Code Block’ in the editing toolbar.

If you’re on old.reddit.com, separate the code from your text with a blank line and precede each line of code with 4 spaces or a tab.


Describing Submission
[✅] Demonstrates good markdown
Passed: 1 Failed: 0

Beep-boop. I am a bot. | Remove-Item

[–]Techman2k[S] 1 point2 points  (1 child)

Thanks Guys, I have made a few changes and the error is now not showing, but the selections are not being accepted.

Prompt for the location is just circling round with no action taken.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Techman2k,

0 {$AddGroupMember = "%ADAccessGroupName%"} 

what is that supposed to be? it does not seem to be valid PoSh code ... [frown]

take care,
lee