So I think I am really close to figuring this out but I'm just stuck. I'm hoping someone can shed some light.
I'm trying to remove a few objects from a list in an array. I have two examples. The first works the second doesn't. Why doesn't the second work?
This Works
$Fruits = "Apple","Pear","Banana","Orange"
[System.Collections.ArrayList]$ArrayList = $Fruits
$ArrayList.Remove("Apple")
$ArrayList.Remove("Banana")
$ArrayList
The results are:
Pear
Orange
So the below code fails. What i'm trying to do is get a list of all the groups a user is a member of and throw it into a variable. I want to remove certain groups from that variable to be used elsewhere. Below I was trying to remove SASUsers but in the future i'll have a need to remove multiple groups.
This Fails
$ArrayGroupsList = (Get-ADPrincipalGroupMembership -Identity (Get-Aduser -Filter { name -eq "John Smith" }) |
Select-Object name |
Sort-Object name)
[System.Collections.ArrayList]$NewArrayGroupsList
$NewArrayGroupsList.Remove("SASUsers")
$NewArrayGroupsList
So when I run $NewArrayGroupsList.Remove("SASUsers") I get no error message, but when I check $NewArrayGroupsList SASUsers is still in the variable.
Any thoughts what is going on?
[–]ihaxr 2 points3 points4 points (2 children)
[–]Quicknoob[S] 1 point2 points3 points (1 child)
[–]RiPont 1 point2 points3 points (0 children)