<#Created By Abhishek Bansal
Read Note
Script Usage :: Fetching Membership of users from Active Directory.
Pre requisites :: Copy all the code into a text file, save it with an extension ".PS1". On same location create a text file named "InputUserid.txt" which contains User's ID. Once saved, run script as Administrator.
Execution & Outputs :: Once executed Output will be saved in separate files named "UserID_Date.csv" and any Errors into "Errorslogs.csv" onto same location.#>
$inputusers = Get-Content .\InputUserid.txt
$date = $(Get-Date -Format "dd_MM_yyyy")
foreach($user in $inputusers)
{
$user = $user.trim()
try
{
$error.Clear()
$file = "$user"+"_$date"
Get-ADPrincipalGroupMembership -Identity $user | Select-Object -Property Name,GroupScope,GroupCategory,DistinguishedName | Export-Csv ./$file.csv -NoTypeInformation
}
catch
{
$user | Select-Object -Property @{n="User ID";e={$user}},@{n="Error Message";e={$Error.exception.Message}} | Export-Csv ./Errorlogs.csv -Append
}
}
No comments:
Post a Comment