Class CustomAdInfo {
$UserName
$Group
$Email
$Manager
}
[char] 'y'..[char] 'z' | ForEach-Object {
$getADUserSplat = @{
Filter = "Name -like '$_*'"
Properties = 'SamAccountName', 'memberOf', 'EmailAddress', 'Manager'
ResultPageSize = 256
SearchBase = 'CN=Users,DC=ab,DC=cd'
}
foreach ($user in Get-ADUser @getADUserSplat) {
foreach ($group in $user.MemberOf | Get-ADGroup) {
[CustomAdInfo]@{
UserName = $user.SamAccountName
Group = $group.Name # <= You need to choose an attribute here
Email = $user.EmailAddress
Manager = $user.Manager
}
}
}
} | Export-Csv 'C:UsersDownloadsMembers_and_Groups.csv'
Above code returns Field Manager value as CN=manager-id,CN=Users,DC=ab,DC=cd in csv. Manager field is bound by CN user type and Domain details. Expectation is to replace these, extract only manager-id from the string and assign it to class property Manager. Am a beginner, couldn’t find anything helpful on the internet. Anyone could help me here?