I am trying to run a script and export the results to csv. The script runs fine onscreen but when the output is sent to the csv file the results for msDS-PrimaryComputer all return "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection".
Here is the script I am running:
Get-ADUser -Filter * -Properties * | Select Name,sAMAccountName,msDS-PrimaryComputer | Export-Csv 'c:\Temp\ADUserPrimaryComputer.csv' -NoTypeInformation
Get-Content "C:\Temp\ADUserPrimaryComputer.csv"
The output is fine on screen but not in the csv file. From my research I gather that this is due to msDS-PrimaryComputer containing a list of values but not being familiar with scripting, I haven't been able to figure out how to make it work. Here is the code I used with -Expand
Get-ADUser -Filter * -Properties * |
Select -Expand msDS-PrimaryComputer
Get-ADUser -Filter * -Properties * |
Name,sAMAccountName,@{N='msDS-PrimaryComputer';E={$_.msDS-PrimaryComputer -join '|'}} |
Export-Csv 'c:\Temp\ADUserPrimaryComputer.csv' -NoTypeInformation
Get-Content "C:\Temp\ADUserPrimaryComputer.csv"
Thanks in advance for any help you can provide.