<#Created By Abhishek Bansal
Read Note
Script Usage :: Fetching Membership of Multiple AD Group at once.
Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1". On same location create a text file named "Input.txt" which contains AD Group names. Once saved, run script as Administrator.
Execution & Outputs :: Output will be saved into separate files named "Groupname.csv" and any error logs into Errorlogs.csv #>
$grp = Get-Content .\Input.txt
foreach($groupname in $grp)
{
$groupname = $groupname.Trim()
$error.Clear()
try{
$membership = Get-ADGroupMember -Identity $groupname | Select Name,Samaccountname,DistinguishedName,@{n="ObjectType";e={$_.objectClass}}
$membership | Export-Csv ./$groupname.csv -NoTypeInformation -Append
}
catch
{
$groupname | Select-Object -Property @{n="Groupname";e={$groupname}},@{n="Error Message";e={$error.exception.Message}} | Export-Csv ./Errorlogs.csv -Append -NoTypeInformation
}
}
No comments:
Post a Comment