How to export users with blank password to CSV


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

Thanks. And apologies for cross-forum posting. From the initial reply on the technet website I wasn’t expecting a further follow up.

But if anyone does know how to export the output I see on the screen to a file (without me having to copy and paste the screen contents), that would be helpful.

Get-Help Out-File
Get-Help Start-Transcript

I replied on the other forum too. Here’s another way to setup an object with 2 properties that works with export-csv:

Get-ADUser -Filter * -ResultSetSize 10 | foreach {
     SamAccountName = $_.SamAccountName
     BlankPassword = (new-object directoryservices.directoryentry "",
       ("domain\" + $_.SamAccountName), "") -ne $null

SamAccountName BlankPassword
-------------- -------------
user1                  False
user2                  False
user3                  False