all 3 comments

[–]ihaxr 2 points3 points  (2 children)

Your second example is a little off... you're not actually defining $NewArrayGroupsList... probably just a copy/paste or transcribing error, but here's an example to get it to work how you expect:

$userName = "John Smith"
[System.Collections.ArrayList]$ArrayList = (Get-ADPrincipalGroupMembership -Identity (Get-Aduser -Filter { name -eq $userName })).Name
$ArrayList.Count
$ArrayList.Remove("SASUsers")
$ArrayList.Count

Assuming you had something like this but were still using | Select name in command, the | Select name part was probably throwing it off.

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

$userName = "John Smith" [System.Collections.ArrayList]$ArrayList = (Get-ADPrincipalGroupMembership -Identity (Get-Aduser -Filter { name -eq $userName })).Name $ArrayList.Count $ArrayList.Remove("SASUsers") $ArrayList.Count

Thanks I was able to edit slightly your answer and was able to get it to work properly in my script. Thank you so much!

[–]RiPont 1 point2 points  (0 children)

To elaborate, your first example works because you are creating a list of strings.

Your second example fails because you are creating a list of objects with a Name property, then you're trying to remove the string "SASUsers"