Created
November 3, 2020 15:41
-
-
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.
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
# 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