Thanks. anything you find will be helpful. Its so close.
Learning more as we go so thank you for that as well
Thanks. anything you find will be helpful. Its so close.
Learning more as we go so thank you for that as well
OK, if I got it right there are one or more DistinguishedNames in the attribute secretary
, right?
Then something like this should work:
$OUName = "OU=Here"
$CSVName = "C:\Export.csv"
$UserList =
Get-QADUser -SearchRoot $OUName -SizeLimit 0 -IncludedProperties Secretary
$Report =
foreach ($User in $UserList ) {
foreach ($Secretary in $User.secretary ) {
$ADSecretary = Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display
[PSCustomObject]@{
'Employee Initals' = $User.SamAccountName
'Secretary' = $ADSecretary.'firstname-lastname-display'
}
}
}
$Report |
Export-Csv -Path $CSVName -NoTypeInformation -Force -Encoding UTF8
Thanks mate. This is mega close. So when i run the code
I changed the code to below.
'Secretary' = $ADSecretary.displayname
When the code runs and it exports the data as an example i see.
âEmployee Initalsâ,âSecretaryâ
âteâ,"Goodman, Steven "
âteâ,âMcFarlane, Craigâ
What i need to see is
âEmployee Initalsâ,âSecretaryâ
âteâ,"Goodman, Steven , McFarlane, Craig "
The code as it stands right now is below.
$UserList =
Get-QADUser -SearchRoot $OUName -SizeLimit 0 -IncludedProperties Secretary , firstname-lastname-display
$Report =
foreach ($User in $UserList ) {
foreach ($Secretary in $User.secretary ) {
$ADSecretary = Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display
[PSCustomObject]@{
'Employee Initals' = $User.SamAccountName
'Secretary' = $ADSecretary.displayname
}
}
}
$Report |
Export-Csv -Path $CSVName -NoTypeInformation -Force -Encoding UTF8
$Report =
foreach ($User in $UserList ) {
$SecretaryList =
foreach ($Secretary in $User.secretary ) {
(Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display).displayname
}
[PSCustomObject]@{
'Employee Initals' = $User.SamAccountName
'Secretary' = $SecretaryList -join ', '
}
}
Hi , No i had tried that but it was still on two lines. I have copied your full code but still the same
If I wanted to be polite Iâd say âThatâs V E R Y unlikelyâ ⌠Are you sure you donât use and older code version?
Start with a new PS session and remove the old CSV file before you run the new code.
I still donât understand why we are insisting on using the quest commands? Sure they were great when powershell was new and lacking, but now it seems like a bad choice, IMHO.
Since I cannot validate this I tend to believe it for now.
But since the data comes from AD it is not necessary to get the desired information.