Author Posts

October 23, 2017 at 5:49 pm

Hi All,

I was using below script to fetch office 365 health status report it was working as expected till the day.
We enabled MFA and now the script is not working.

can someone help in this, how shall I authenticate the API in MFA enabled environment.

URL: https://blogs.technet.microsoft.com/cammurray/2014/09/23/using-powershell-to-obtain-your-tenants-office365-health-dashboard/

$cred = get-credential
$jsonPayload = (@{userName=$cred.username;password=$cred.GetNetworkCredential().password;} | convertto-json).tostring()
$cookie = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/Register" -body $jsonPayload).RegistrationCookie

$jsonPayload = (@{lastCookie=$cookie;locale="en-US";preferredEventTypes=@(0,1)} | convertto-json).tostring()
$events = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/GetEvents" -body $jsonPayload)

Thank you in advance

October 23, 2017 at 7:22 pm

Try this:

https://technet.microsoft.com/en-us/library/mt775114(v=exchg.160).aspx

Additionally you could look at creating a claims rule on your ADFS server to not require MFA for powershell, or a specific internal network range.