How to export screen information to CSV


  • Hi,

    I found a script to show all users who have a blank password. I have tried to export this to a CSV but the information in the export is not what is shown on-screen (see code below). On screen I see each username with True or False below it. In the CSV it has the word "Length" and then a list of numbers. What I'd ideally like to do is export all users who show as having a blank password (TRUE) to a CSV. Can anyone help please?

    $results = Get-ADUser -Filter * -SearchBase "OU=test,DC=lan" | ForEach {
       (new-object directoryservices.directoryentry "", ("domain\" + $_.SamAccountName), "") -ne $null
       Write-Host ""
    $results | Export-Csv C:\PasswordReports\blankpasswords.csv -NoTypeInformation

    Monday, November 26, 2018 1:08 PM


  • This would be one way to make your code output an object with two properties, that can be used with export-csv:

    $results = Get-ADUser -Filter * -SearchBase "OU=test,DC=lan" | 
    select SamAccountName, @{n='BlankPassword';e={ (new-object directoryservices.directoryentry "",
    ("domain\" + $_.SamAccountName), "") -ne $null } } $results | Export-Csv C:\PasswordReports\blankpasswords.csv -NoTypeInformation
    • Edited by JS2010 Monday, November 26, 2018 5:53 PM
    • Marked as answer by scaryfruit Monday, November 26, 2018 8:52 PM
    Monday, November 26, 2018 5:49 PM

All replies