Skip to content

Instantly share code, notes, and snippets.

@poiriersimon
Created January 9, 2019 15:38
Show Gist options
  • Save poiriersimon/5507d0fd46284fa68b1e10d7c340c8df to your computer and use it in GitHub Desktop.
Save poiriersimon/5507d0fd46284fa68b1e10d7c340c8df to your computer and use it in GitHub Desktop.
O365 Check for user that doesn't have password Expiration and aren't using Strong Password
#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)"}}
#3 - for each of those domain - Get-MSOLUser | where{$_.PasswordNeverExpire -eq $TRUE}
[array]$UnsafeUsers = $Users | where {$_.PasswordNeverExpires -eq $True -and StrongPasswordRequired -eq $False}
#4 - if any Trigger
If($UnsafeUsers.count -eq 0){Write-host "Pass"} Else {Write-host "Fail : You have $($UnsafeUsers.count) account"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment