Share via

PowerShell - Get-Localuser PasswordExpires

Sergio Siqueira 41 Reputation points
2024-01-17T11:00:25.0533333+00:00

Hi Guys How do I check if the local user has "password expires" true or false? User's image

Thank you very much in advance

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Castorix31 91,876 Reputation points
    2024-09-12T01:49:55.62+00:00

    On Windows 10 22H2, this works for me :

    Get-WmiObject -Class Win32_UserAccount -Filter "Name='your_username'" | Select-Object Name, PasswordExpires 
    
    

    Was this answer helpful?


  2. Shashank Kumar Srivastava 0 Reputation points Student Ambassador
    2024-01-17T11:15:18.8733333+00:00
    # Specify the username you want to check
    $userName = "YourUsername"
    
    # Get information about the local user
    $user = Get-LocalUser -Name $userName
    
    # Check the PasswordNeverExpires property
    if ($user.PasswordNeverExpires) {
        Write-Host "$userName has 'Password never expires' set to true."
    } else {
        Write-Host "$userName has 'Password never expires' set to false."
    }
    
    
    

    Replace "YourUsername" with the actual username you want to check. The PasswordNeverExpires property of the Get-LocalUser cmdlet will be True if the password never expires, and False otherwise. @Sergio Siqueira

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.