Hi All bit of an odd one, i can get the data to look exactly how i want it in the Array, however exporting to CSV gives something wiered
Import-Module ActiveDirectory $users = Get-ADUser -Filter * -SearchBase "ou=newcastle, OU=United Kingdom,OU=Europe,DC=global,DC=contoso,DC=com" -Properties mail, title,telephonenumber, physicalDeliveryOfficeName, employeeid | ? {$_.employeeid -like "0*"} | select mail, title,telephonenumber, physicalDeliveryOfficeName, givenname,surname $outarray = @() foreach ($user in $users) { $properties = @{'First Name' = $User.givenname 'Last Name' = $User.Surname 'E-Mail Address' = $user.mail 'Job Title' = $user.title 'Business Phone' = $user.telephonenumber 'Office' = $user.physicalDeliveryOfficeName } $Obj = New-Object -TypeName psobject -Property $properties Write-Output $obj $outarray += $obj } $result = $outarray | ft 'first name', 'last name', 'e-mail address', 'business phone', 'office' $result | Export-Csv c:\temp\Proxyclick.csv
typing $Result displays correctly, colums sorted and formatted
First Name Last Name E-Mail Address Business Phone Office ---------- --------- -------------- -------------- ------ Lloyd Pickering Lloyd.Pickering@contoso.com +44 191 238 xxxx Newcastle Office Gillian Wright Gillian.Wright@contoso.com +44 191 238 xxxx Newcastle Office Daren Carr Daren.Carr@contoso.com +44 191 238 xxxx Newcastle Office Andrew Hales-Hill Andrew.Hales-Hill@contoso.com +44 191 479 xxxx Newcastle Office
however the csv looks like
#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData ClassId2e4f51ef21dd47e99d3c952918aff9cd pageHeaderEntry pageFooterEntry autosizeInfo shapeInfo groupingEntry 033ecb2bc07a4d43b5ef94ed5a35d280 Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo 9e210fe47d09416682b841769c78b8a3 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c 27c87ef9bbda4f709f6b4002fa4af63c
without the sorting section, it exports fine
$result = $outarray | ft 'first name', 'last name', 'e-mail address', 'business phone', 'office'