I extract a list of departments from AD like this using PowerShell:
$departments = Get-ADUser -Filter * -Property Department |
Where-Object { $_.Department } |
Select -Expand Department -Unique
At the end of this operation, if I input on the console $departments
I get all the names of the departments as I wished. But if I try to export this to a .csv file using
| Export-Csv H:\TEST\DEPTAAAAA.csv
I get this
#TYPE System.String
Length
4
9
5
13
13
13
How can I export the department names stored in the $departments
so the output is a .csv file containing the department names?