Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to refer to individual objects in a variable

$
0
0

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


Viewing all articles
Browse latest Browse all 6937

Trending Articles