Adrian Z.
Adrian Z.

Reputation: 934

Extra keys in export-csv in powershell

I'm using Get-ADUser with Filter and Properties parameters to export all my users from the active directory and then export them to csv with Export-Csv. This adds five extra keys to the dictionary of each user.

'PSShowComputerName':'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection',
'WriteVerboseStream':'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection',
'WriteWarningStream':'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection',
'WriteDebugStream':'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection',
'WriteErrorStream':'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection'

While I'm just asking for the following properties:

CN, GivenName, Surname, DisplayName, DistinguishedName, Description, Created, WhenCreated, 
Enabled, LockedOut, PasswordLastSet, LastLogonDate, PasswordNeverExpires, 
CannotChangePassword, accountExpires, Initials, LogonHours

Why does it do that and how can I remove them?

Code:

$aduser = Get-ADUser `
            -Filter * `
            -Properties CN, GivenName, Surname, DisplayName, DistinguishedName, Description, Created, WhenCreated, 
                        Enabled, LockedOut, PasswordLastSet, LastLogonDate, PasswordNeverExpires, 
                        CannotChangePassword, accountExpires, Initials, LogonHours
$aduser | Export-Csv "E:\adusers.csv" -Encoding Unicode -Delimiter ";"

Upvotes: 0

Views: 505

Answers (1)

tfonias74
tfonias74

Reputation: 136

By using the following you can manipulate the output as you see fit:

$aduser | Select DisplayName,Created,LockedOut | Export-Csv ".....

In the select part use can specify all the attributes you want and in the order you want!

Upvotes: 2

Related Questions