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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,512 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. 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


  2. Castorix31 84,546 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 
    
    

Your answer

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