Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Active Directory user properties blank in CSV export

$
0
0

Hi,

I'm working on a script to export some properties of user accounts and export them to CSV, but, strangely, some of these properties are blank in the output, while they are set when I display them from the PS console. Here's the relevant snippet of my code:

$user = Get-ADUser -Filter 'samaccountname -like $username'

    $obj = New-Object -TypeName PSObject
    $obj | Add-Member -MemberType NoteProperty -Name UserName -Value $username
    $obj | Add-Member -MemberType NoteProperty -Name UserSurname -Value $user.surname
    $obj | Add-Member -MemberType NoteProperty -Name UserGivenName -Value $user.givenname
    $obj | Add-Member -MemberType NoteProperty -Name UserStatus -Value $user.Enabled
    $obj | Add-Member -MemberType NoteProperty -Name PwdExp -Value $user.PasswordExpired
    $obj | Add-Member -MemberType NoteProperty -Name Locked -Value $user.LockedOut
    $obj | Add-Member -MemberType NoteProperty -Name WhenUserChanged -Value $user.whenChanged

    $out += $obj
[...]

$out | Export-Csv .\UserStatus.csv -NoTypeInformation

Now, the last three columns (PasswordExpired, LockedOut, whenChanged) are blank, so a line would look like this:

"UserName","UserSurname","UserGivenName","UserStatus","PwdExp","Locked","WhenUserChanged"
"accountname","lastname","firstname","True",,,

Any idea?

Thanks!


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>