Created
January 9, 2019 15:37
-
-
Save poiriersimon/fd597fb66cd2743b8c898e2252721be9 to your computer and use it in GitHub Desktop.
O365 Check Password Policy for Managed Domains
This file contains hidden or 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
#1 - List Managed Domain | |
$ManagedDomain = Get-MSOLDomain |where {$_.AuthenticationType -eq "Managed"} | |
#2 - Check if 1 users exist in those domain | |
$UsedManagedDomains = @() | |
foreach ($ManagedDomain in $ManagedDomains){$Users = @(); $users= Get-MSOLUser -All | where {$_.UserPrincipalName -like "*$($ManagedDomain.name)"} | select -First 1;if($Users.count -gt 0){$UsedManagedDomains+=$ManagedDomain}} | |
#3 - List Password Policies for all managed domain with at least 1 user | |
$NoPasswordPolicyDomain = @() | |
foreach($UsedManagedDomain in $UsedManagedDomain){$PasswordPolicy = Get-MsolPasswordPolicy -DomainName $ManagedDomain.name; if($PasswordPolicy.NotificationDays -eq $NULL -and $PasswordPolicy.ValidityPeriod -eq $NULL){$NoPasswordPolicyDomain += $UsedManagedDomain}} | |
#4 - If Password policy is not complex - Trigger | |
If($NoPasswordPolicyDomain.count -eq 0){Write-host "PASS"}Else{Write-host "FAIL for Domain(s) : $($NoPasswordPolicyDomain.name -join ', ')" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment