The duplicate column was just a name missing a space between "Gerente" and "Sireto" in the hash.
Try this version (slightly modified). If you're still not getting the manager's display name you'll have to have a look at the object returned by the Get-ADUser to be sure that "manager" is the property you're looking for. It should contain the distinguishedName of the user's manager.
Yes, you can combine the names. But I'll leave that up to you. You can use either the "format" operator ("-f") or simple string concatenation to do it.
$DN = 'OU=Brasilien,OU=Others,OU=Users,OU=Leschaco,DC=hq,DC=LESCHACO,DC=org' #usuários BR
$Props = [ordered]@{
Nome = ""
Sobrenome = ""
'Citrix ID' = ""
'E-mail' = ""
Departamento = ""
Cargo = ""
'Gerente Sireto' = ""
'Status Conta' = ""
'Member Of' = ""
}
Get-ADUser -filter * -SearchBase $DN -Property Department, Title, Manager |
ForEach-Object{
$Props.Nome = $_.givenName
$Props.Sobrenome = $_.Surname
$Props."Citrix ID" = $_.SamAccountName
$Props."E-mail" = $_.UserPrincipalName
$Props.Departamento = ($_| Select-Object -Expand Department)
$Props.Cargo = ($_ | Select-Object -Expand title) #Corrigir isso
Try{
$Props."Gerente Direto" = (Get-ADUser -Identity $_.manager -ErrorAction STOP | Select-Object -Expand DisplayName) #Corrigir isso
}
Catch{
$Props."Gerente Direto" = ""
}
$Props."Status Conta" = $_.Enabled
Get-ADPrincipalGroupMembership -Identity $_.samaccountname |
ForEach-Object{
$Props."Member Of" = ($_ | Select-Object -ExpandProperty Name)
[PSCustomObject]$Props
}
} | Export-CSV c:\temp\UserAndGroup.csv -NoTypeInformation
Get-ADUser -Filter * -SearchBase $DN -Properties name,memberof |
Select-Object name,memberof |
Sort-Object -Property name |
Format-Table -AutoSize