Last active
November 3, 2020 15:41
-
-
Save roberttoups/bd0783f605ced80e07ce68903a99ef5c to your computer and use it in GitHub Desktop.
PowerShell snippet to export accounts to CSV outside the default domain password policy in Active Directory
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-ExceedsDomainPasswordAge.ps1 | |
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss' | |
$MaxPasswordAgeInDays = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days | |
$MaxAgeDate = (Get-Date).AddDays(- $MaxPasswordAgeInDays) | |
$PropertyList = @('Enabled','PasswordLastSet','Name','GivenName','SurName','SamAccountName','UserPrincipalName','DistinguishedName','manager') | |
[System.Array]$ExportData = Get-ADUser -Filter { PasswordLastSet -lt $MaxAgeDate -or PasswordLastSet -notlike '*' } -Properties $PropertyList | |
$ExportData | | |
Select-Object -Property $PropertyList | | |
Export-Csv -Path (Join-Path -Path '.' -ChildPath "$TimeStamp-PasswordAgeOutsidePolicyAccounts.csv") -NoTypeInformation | |
Write-Host "$($ExportData.Count.ToString('#,##0')) accounts are outside of the Domain Password Policy Age of $MaxPasswordAgeInDays days." -ForegroundColor 'Red' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment