I'm still trying to learn PowerShell and this is giving me fits.
I can get a list of all the groups that a user is a member of but I'm having
trouble getting it to only return a select list of groups.
I have a txt file with a list of user IDs. I would like to find out all the
users that belong to security groups A, B or C.
Here is what I have to process the list of users and return all the groups that
they are members off. Now I want to find out is these users are a member of
only 3 or 4 different groups. I tried to put a Where-Object after the last
ForEach and before the Add-Member items, but that didn't work.
$out = @()
Get-Content "C:\Temp\UserIDs2.txt" | ForEach {
$username = $_
$groups = Get-ADPrincipalGroupMembership $username
ForEach ( $group in $groups ) {
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name UserName -Value $username
$obj | Add-Member -MemberType NoteProperty -Name GroupName -Value $group.name
# $obj | Add-Member -MemberType NoteProperty -Name Description -Value
$group.description
$out += $obj
}
}
$out | Out-file "C:\Temp\UserIDsGroupMembership2.txt"
Ken Lutz
Senior Systems Administrator
Information Systems Department
Spokane County
815 N. Jefferson
Spokane, Washington 99260
[cid:[email protected]]
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1