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

Help with extra detail for script
Last Post 06 May 2008 02:17 AM by cheylanz. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
cheylanzUser is Offline
New Member
New Member
Posts:2

--
28 Apr 2008 02:37 AM  

Hello All,

I am totally new to Powershell however I have done one script that gives me what group membership a particular user is a member of however I am wondering how I go about also adding a little more detail like their Username,   Telephone number and Manger.  The script I have at the moment for membership is:

 

$user = Read-Host "User Account"
$search = [System.DirectoryServices.DirectorySearcher]"LDAP://DC=domainname1,DC=domainname2,DC=domainname3,DC=domainname4 ,OU=Domain Users ,OU=General Users"
$search.Filter = "(samAccountName=$user)"
$result = $search.FindOne()
$usr= $result.getDirectoryEntry()
$grps = $usr.MemberOf
foreach ($grp in $grps){
 $grpstr = "LDAP://$grp"
 $g = [ADSI]$grpstr
 $g.cn >> c:\Groups.txt
}

 

Thank you

Cheyla

valdezdjUser is Offline
New Member
New Member
Posts:62

--
30 Apr 2008 05:24 PM  
If you're going to be working in AD, I would recommend that you download the snapin Quest.ActiveRoles.ADManagement. It just makes it so much easier to pull information from AD with this snapin. It also comes with a complete guide on how to use the cmdlets. Just to go to Directories, Products and Services, then click on the link that'll take you to the download.
But if you decide not to do that, try doing:

$g.cn|ft samaccountname, telephonenumber, manager
bsonposhUser is Offline
Basic Member
Basic Member
Posts:388

--
30 Apr 2008 06:55 PM  
Try this... I fixed your search filter and added the properties.

$user = Read-Host "User Account"
$search = new-object System.DirectoryServices.DirectorySearcher([ADSI]"","(&(objectcategory=user)(samAccountName=$user))")
$usr = ($search.FindOne()).getDirectoryEntry()
$grps = $usr.MemberOf
"LogonName : {0}" -f $usr.psbase.properties.item('sAMAccountName').toString()
"Telephone : {0}" -f $usr.psbase.properties.item('telePhoneNumber').toString()
"Manager : {0}" -f $usr.psbase.properties.item('manager').toString()
foreach ($grp in $grps){
$grpstr = "LDAP://$grp"
$g = [ADSI]$grpstr
"Memberof : {0}" -f $g.psbase.properties.item('cn').toString()
}
cheylanzUser is Offline
New Member
New Member
Posts:2

--
06 May 2008 02:17 AM  

Thank you so much.  Worked like a charm.

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