Get-ADInfo.psm1
<#
.Synopsis Cmdlet for gathering AD User information. .Description Get-UserInfo lists important information about Active Directory Users. Includes membership information. .Parameter Name Name of an AD User. .Example # List information about a group Get-UserInfo -Name Administrator .Example # List information about all groups Get-UserInfo -Name * .Link #> function Get-UserInfo{ param($Name) if($Name -eq "*"){ $User = Get-ADUser -Filter * -properties * }else{ $User = Get-ADUser $Name -properties * } foreach($x in $User){ $MemberOf = (Get-ADUser $x -Properties *).MemberOf | %{ ($_ -split "," -like "CN=*" -split "=")[1]} $Write = @" -------------------------------------------------------------- SAM: {0} SID: {1} CN: {2} DN: {3} CREATED: {4} CHANGED: {5} HOME: {6} AUTHENTICATION STATS LAST LOGON: {7} LAST FAILED LOGON: {8} LOGON COUNT: {9} LOCKED OUT: {10} PASS LAST SET: {11} PASS EXPIRED: {12} PASS WORD NEVER EXPIRES: {13} MEMBER OF ------------------------------- "@ -f $x.SamAccountName, $x.SID, $x.CN, $x.DistinguishedName, $x.Created, $x.WhenChanged, $x.HomeDirectory, $x.LastLogonDate, $x.LastBadPasswordAttempt, $x.LogonCount, $x.LockedOut, $x.PasswordLastSet, $x.PasswordExpired, $x.PasswordNeverExpires Write-Host $Write if($MemberOf -gt 0){ foreach($x in $MemberOf){ write-host @" $x "@ } }else{ Write-Host @" NONE "@ } Write-Host } } <# .Synopsis Cmdlet for gathering AD Group information. .Description Get-GroupInfo lists important information about Active Directory Groups. Includes membership information. .Parameter Name Name of an AD Group. .Example # List information about a group Get-GroupInfo -Name Administrators .Example # List information about all groups Get-GroupInfo -Name * .Link #> function Get-GroupInfo{ param($Name) if($Name -eq "*"){ $Group = Get-AdGroup -Filter * -Properties * }else{ $Group = Get-ADGroup "$Name" -Properties * } foreach($x in $Group){ $GroupMembers = Get-ADGroupMember $x.Name | % SamAccountName $MemberOf = (Get-AdGroup $x.Name -properties *).MemberOf $Write = @" -------------------------------------------------------------- GROUP: {0} SID: {1} DN: {2} CREATED: {3} CHANGED: {4} DESCRIPTION: {5} MEMBER OF ------------------------------- "@ -f $x.CN, $x.SID, $x.DistinguishedName, $x.Created, $x.WhenChanged, $x.Description Write-Host $Write if($MemberOf -gt 0){ foreach($x in $MemberOf){ $MemberSplit = ($x -split "," -like "CN=*" -split "=")[1] write-host @" $MemberSplit "@ } }else{ write-host @" NONE "@ } Write-Host @" MEMBERS ------------------------------- "@ if($GroupMembers -gt 0){ foreach($x in $GroupMembers){ write-Host @" $x "@ } }else{ write-Host @" NONE "@ } $GroupMembers = $Null $MemberOf = $Null Write-Host } } |