ceturtdiena, 2013. gada 30. maijs

PowerShell script to show AD Domain group members

I needed a users in Active Directory Domain group, in nice columns, I did not found satisfactory examples so I had to write it myself. Besides I needed some properties of user. Command Get-ADGroupMembers <groupname> shows all standard parameters of user but I needed description and if user is enabled.


$Users = Get-ADGroupMember BLP_LDAP
foreach ($User in $Users)
{
 Get-ADUser $User.SamAccountName -Properties * | select Name,SamAccountName,Description,Enabled
}



If you want to see other parameters of user, first get the name of  parameter, and then put them in script after comma.

 Get-ADUser <username> -Properties *

Later it turns in to monster because managers wanted to know which user belongs to which groups. I can expect it script seems weird but it works.

$Users = Get-ADUser  -Filter 'enabled -eq $true'
foreach ($User in $Users)
{
 Get-ADUser $User.SamAccountName -Properties * |select DisplayName,SamAccountName
 Get-ADUser $User.SamAccountName -Properties MemberOf|Select-Object -ExpandProperty MemberOf

}

Nav komentāru:

Ierakstīt komentāru