Skip to content

Instantly share code, notes, and snippets.

@roberttoups
Created November 3, 2020 15:41
Show Gist options
  • Save roberttoups/ddde05fb68ca01f82265991a04223d27 to your computer and use it in GitHub Desktop.
Save roberttoups/ddde05fb68ca01f82265991a04223d27 to your computer and use it in GitHub Desktop.
PowerShell snippet to export user objects to CSV that have their password set to never expire.
# Export-PasswordNeverExpires.ps1
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss'
$PropertyList = @('Enabled', 'PasswordLastSet', 'Name', 'GivenName', 'SurName', 'SamAccountName', 'UserPrincipalName','DistinguishedName', 'manager')
[System.Array]$ExportData = Get-ADUser -Filter { PasswordNeverExpires -eq $true } -Properties $PropertyList
$ExportData |
Select-Object -Property $PropertyList |
Export-Csv -Path (Join-Path -Path '.' -ChildPath "$TimeStamp-PasswordNeverExpiresAccounts.csv") -NoTypeInformation
Write-Host "$($ExportData.Count.ToString('#,##0')) accounts are set to password never expires." -ForegroundColor 'Red'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment