{"id":1873,"date":"2022-05-07T13:23:55","date_gmt":"2022-05-07T11:23:55","guid":{"rendered":"https:\/\/leeryanrs.com\/?p=1873"},"modified":"2022-05-07T13:23:55","modified_gmt":"2022-05-07T11:23:55","slug":"check-password-expiry-office365","status":"publish","type":"post","link":"https:\/\/leeryanrs.com\/?p=1873","title":{"rendered":"Check password expiry Office365"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">$cred = Get-Credential &#8220;your.credentials@company.com&#8221;<br> <br>Connect-MsolService -Credential $cred<br> <br>$domain = Get-MsolDomain | where {$_.IsDefault -eq $true}<br> <br>$PasswordPolicy = Get-MsolPasswordPolicy -DomainName $domain.Name<br> <br>$Account = &#8220;Account.ToCheck@company.com&#8221; # Change HERE !!<br> <br>$UserPrincipal  = Get-MsolUser -UserPrincipalName $Account<br> <br>$UserPrincipal | fl PasswordNeverExpires<br> <br>$PasswordExpirationDate = $UserPrincipal.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)<br> <br>Write-host &#8220;Password will Expire on : $PasswordExpirationDate&#8221;<br> <br>$StartDate = (GET-DATE)<br>$DaysLeft = NEW-TIMESPAN -Start $StartDate -End $PasswordExpirationDate<br>$DaysLeft = [math]::Floor($DaysLeft.TotalDays)<br> <br>Write-host &#8220;Password will Expire in # Days : $DaysLeft&#8221;<br> <br>$UserPrincipal | select DisplayName, LastPasswordChangeTimeStamp,@{Name=\u201dPasswordAge\u201d;Expression={((Get-Date).ToUniversalTime())-$_.LastPasswordChangeTimeStamp}} | sort-object PasswordAge -desc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>$cred = Get-Credential &#8220;your.credentials@company.com&#8221; Connect-MsolService -Credential $cred $domain = Get-MsolDomain | where {$_.IsDefault -eq $true} $PasswordPolicy = Get-MsolPasswordPolicy -DomainName $domain.Name $Account = &#8220;Account.ToCheck@company.com&#8221; # Change HERE !! $UserPrincipal = Get-MsolUser -UserPrincipalName $Account $UserPrincipal | fl PasswordNeverExpires $PasswordExpirationDate = $UserPrincipal.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod) Write-host &#8220;Password will Expire on : $PasswordExpirationDate&#8221; $StartDate = (GET-DATE)$DaysLeft = NEW-TIMESPAN -Start $StartDate -End $PasswordExpirationDate$DaysLeft [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[37,38,51],"class_list":["post-1873","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-office365","tag-powershell","tag-windows"],"_links":{"self":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts\/1873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1873"}],"version-history":[{"count":0,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=\/wp\/v2\/posts\/1873\/revisions"}],"wp:attachment":[{"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leeryanrs.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}