I am trying to write a function which will be used to remove groups from an AD user account, and I am having trouble with part of the syntax. I need to know how to refer to an individual object within a variable containing numerous objects, and wondering if anyone can point me in the right direction? The "($group in $groups)" portion of the script below is where I am trying to do this, but I know it is not correct yet.
$groups = (Get-ADUser $User -Properties MemberOf | Select-Object MemberOf).MemberOf
$groups | ForEach-Object ($group in $groups) {IF ($group -ne "Domain Users") {write-host $group.name}}
I am still a fairly new powershell user, so if you could refrain from using aliases, etc in your responses, I will be able to follow things much easier.
Thanks,
Andrew