How to export users with blank password to CSV

Welcome Forums General PowerShell Q&A How to export users with blank password to CSV

This topic contains 4 replies, has 3 voices, and was last updated by

js
 
Participant
4 months, 3 weeks ago.

  • Author
    Posts
  • #126570

    Participant
    Points: -5
    Rank: Member

    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 {
    $_.SamAccountName
    (new-object directoryservices.directoryentry "", ("domain\" + $_.SamAccountName), "").psbase.name -ne $null
    Write-Host ""
    }
    $results | Export-Csv C:\PasswordReports\blankpasswords.csv -NoTypeInformation
  • #126579

    Participant
    Points: 1,373
    Helping Hand
    Rank: Community Hero
    • #126593

      Participant
      Points: -5
      Rank: Member

      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.

  • #126596

    Participant
    Points: 1,373
    Helping Hand
    Rank: Community Hero
    Get-Help Out-File
    Get-Help Start-Transcript
  • #126623
    js

    Participant
    Points: 962
    Helping Hand
    Rank: Major Contributor

    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 {
       [pscustomobject]@{
         SamAccountName = $_.SamAccountName
         BlankPassword = (new-object directoryservices.directoryentry "",
           ("domain\" + $_.SamAccountName), "").psbase.name -ne $null
         }
    }
    
    
    SamAccountName BlankPassword
    -------------- -------------
    user1                  False
    user2                  False
    user3                  False
    

The topic ‘How to export users with blank password to CSV’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort