Friday, March 23, 2018

Group Membership Report – PowerShell Script

Another “Group Membership Report” script.  You can see some of the previous versions here - http://portal.sivarajan.com/2010/08/list-group-members-in-active.html.

This script provides the group membership details based on user name.  You can include all user names in an input file (Users.csv) in the following format:















Script uses Get-ADUser cmdlet to validate the user first then get the user membership using the “memberof” properties.  Output/report will be in the GMReport_$Cdate.csv file.  Error message will be captured in Error_$Cdate.csv file.

Script:
#
#Group Membership Report – PowerShell Script
#Santhosh Sivarajan (santhosh@sivarajan.com)
#
Clear
Import-Module ActiveDirectory
$userN = ""
$GroupDetails = ""
$Group = ""
$GroupsDN = ""
$uValidation = ""
$Cdate = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")

    $Report = New-Item -type file -force "C:\Temp\GMReport_$Cdate.csv"
    Import-CSV "C:\Temp\Users.csv" | % {
    $userN = $_.userName
    $sourceDomain = $_.Domain
    $uValidation = Get-ADUser -filter {sAMAccountName -eq $userN} -Server $sourceDomain
   
        If($uValidation -eq $Null)
             {
              Write-Host "User $userN Doesn't Exist in $sourceDomain Domain"
              $errorFile = New-Item -type file -force "C:\Temp\Error_$Cdate.csv"
              "User $userN Doesn't Exist in $sourceDomain Domain"| Out-File $errorFile -encoding ASCII -append
             }
         Else
             {
               
                $userN | Out-File $SGBeforeUpdateFile -encoding ASCII -append
                $GroupDetails = get-aduser -Server $sourceDomain -identity $userN -Properties memberof
                $GroupsDN = $GroupDetails.memberof
                $GroupsDN | Out-File $SGBeforeUpdateFile -encoding ASCII -append
            }
    }

Download:
You can also download the script from the following locations:
  1. OneDrive
  2. TechNet Gallery 

1 comments:

Quel est notre produit? - La meilleure marque de luxe au monde regarde des kopie horloges de la plus haute qualité! Si vous voulez avoir ces Kopie Horloges IWC de luxe, vous voulez porter ces montres sur votre poignet, mais arrêtez-vous en raison de leur prix élevé. Alors s'il vous plaît arrêtez vos pas, c'est votre endroit le plus correct..

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More