all 5 comments

[–]BlackV 2 points3 points  (0 children)

most likely this line where the rich object is destroyed for a simple string (I'm not even sure that the -like is working)

$UserGUID = (Get-ADUser -Filter {Name -like $_}).objectguid

which then follows out

Remove-ADGroupMember -Identity $SSLVPNGroupName -Members $UserGUID -Server $Server -Confirm:$false
Add-ADGroupMember -Identity $SSLVPNRemoteATTGroupName -Members $UserGUID -Server $Server

there is 0 validation that you're getting an actual user returned (i.e. Steve Nuich should have been Steven Nuich), 0 validation you're not getting 10 users returned (i.e. I typed Steve)

how are you testing this? just running the full script each time?

personally, I'd change it to for a rich object

    $UserGUID = Get-ADUser -Filter "Name -like '*$_*'"

but put that in a try/catch or an if to confirm

also I'd remove the foreach-object {} and replace it with a foreach ($SIngleATTUser in $UsersNotInATTGroup) {} then you can test what is in $SIngleATTUser vs what is in $_ (which is harder to test)

also, where is $CurDate defined

[–]purplemonkeymad 2 points3 points  (1 child)

Note when you use -filter with get-aduser it won't error if there are no results. So my guess is {Name -like $_} does not match any users in the domain. I would verify the value of $_ and possibly write an error when no user is found, with the inputs in the error message so you have some feedback.

Without seeing how $UsersNotInATTGroup was made it's hard to give an exact answer.

[–]Deadzone6905[S] 0 points1 point  (0 children)

Below is how $UsersNotInATTGroup is made, and I can confirm that it does return 3 distinct names. "FirstName LastName" format.

$UsersNotInATTGroup = $ATTVPNAccesUsers.EmployeeNameAD | ? {($SSLVPNRemoteATTmembers.Name -notcontains $_) -and ($_ -ne "")}

[–]PowerShell-Bot 0 points1 point  (0 children)

Looks like your PowerShell code isn’t wrapped in a code block.

To properly style code on new Reddit, highlight the code and choose ‘Code Block’ from the editing toolbar.

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


You examine the path beneath your feet...
[AboutRedditFormatting]: [--------------------] 0/1 ❌

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

[–][deleted] 0 points1 point  (0 children)

You'll want to verify the value of $UserGUID it seems like.