Created
June 19, 2023 00:47
-
-
Save anikwai/8bd24c8690405f7fa04f7ad8c6785b53 to your computer and use it in GitHub Desktop.
ListPasswordNeverExpired
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the Active Directory module if not already loaded | |
if (!(Get-Module -Name ActiveDirectory)) { | |
Import-Module ActiveDirectory | |
} | |
# Get all users where PasswordNeverExpires is set to true and account is enabled | |
$users = Get-ADUser -Filter { PasswordNeverExpires -eq $true -and Enabled -eq $true } -Properties PasswordNeverExpires | |
# Export to CSV | |
$users | Select-Object SamAccountName, PasswordNeverExpires | Export-Csv -Path C:\temp\PasswordNeverExpiresUsers.csv -NoTypeInformation | |
Write-Output "Exported to C:\temp\PasswordNeverExpiresUsers.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment