Skip to content

Instantly share code, notes, and snippets.

@anikwai
Created June 19, 2023 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anikwai/8bd24c8690405f7fa04f7ad8c6785b53 to your computer and use it in GitHub Desktop.
Save anikwai/8bd24c8690405f7fa04f7ad8c6785b53 to your computer and use it in GitHub Desktop.
ListPasswordNeverExpired
# 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