When I run the below code I get a list of details in separate columns.
$file = 'c:\output\testing.csv'
Get-AdUser -filter "DisplayName -eq 'joe bloggs'" |
Get-ADUser -Properties * |
Select-Object givenName, surname, mail,
@{ Label = "Country"
Expression = { if ($_.Country) { $_.Country } else { "GB" } }
,samaccountname, department, description | Export-csv -path $file
Output (1) is as follows:
+-----------+---------+-----------------+---------+----------------+------------+-------------+
| givenName | surname | mail | Country | samaccountname | department | description |
+-----------+---------+-----------------+---------+----------------+------------+-------------+
| joe | bloggs | joe.b@email.com | GB | bloggsG | IT | Support |
+-----------+---------+-----------------+---------+----------------+------------+-------------+
However, if I amend the Export-CSV to Add-Content
, the output (2) is as below:
+---------------------------------------------------------------------------------------------------------------------------------------+---------+------+---------+----------------+------------+-------------+
| givenName | surname | mail | Country | samaccountname | department | description |
| {givenName=Fred; surname=Smith; mail=fred.s@email.com; Country=GB; samaccountname=smithF; department=Facilities; description=cleaner} | | | | | | |
+---------------------------------------------------------------------------------------------------------------------------------------+---------+------+---------+----------------+------------+-------------+
How do I use Add-Content
to show the same output as the first table?