header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

if user is member of group
Last Post 23 Jul 2008 09:25 AM by Shay. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
dlisterjrUser is Offline
New Member
New Member
Posts:2

--
22 Jul 2008 05:04 PM  

I am having a problem figuring out how to show if a user is a member of a group. I am query attributes of all users under a ou and want to show the users is a member or not of the VPNUsers group. This is my current script:

get-qaduser -searchroot $ou.dn -IncludedProperties 'distinguishedName','sAMAccountName','DisplayName','whenCreated','title','info','homeDirectory','accountexpires','lockouttime','mail','department','description' -sizelimit 0 | select-object distinguishedName,sAMAccountName,DisplayName,whenCreated,title,info,homeDirectory,accountexpires,lockouttime,mail,department,description | export-csv $tempDirectory$csvfilename -notypeinformation

Any hep would be appreciated.

ShayUser is Offline
Basic Member
Basic Member
Posts:228

--
23 Jul 2008 09:06 AM  

$VPNUsers = (Get-QADGroup VPNUsers).dn
$MemberOfVPNUsers = @{name="MemberOfVPNUsers";expression={ if ($_.memberOf -contains $VPNUsers) {"Yes"} else {"No"} }}
Get-QADUser -searchRoot $ou.dn | select Name,$MemberOfVPNUsers ,distinguishedName,sAMAccountName,DisplayName,whenCreated,title,info,homeDirectory,accountexpires,lockouttime,mail,department,description | export-csv "$tempDirectory\$csvfilename" -nti

-Shay



ShayUser is Offline
Basic Member
Basic Member
Posts:228

--
23 Jul 2008 09:25 AM  

There is another option, the above will give you only the direct members of the VPNUsers group. You can use the -Indirect parameter to get ALL members even if they are not direct members (nested group members):


$VPNUsers = Get-QADGroupMember "domain admins" -Indirect | foreach {$_.SamAccountName}
$MemberOfVPNUsers = @{name="MemberOfVPNUsers";expression={ if ($VPNUsers -contains $_.SamAccountName) {"Yes"} else {"No"} }}
Get-QADUser -searchRoot $ou.dn | select Name,$MemberOfVPNUsers .....

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer