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.


$cred = get-credential
$jsonPayload = (@{userName=$cred.username;password=$cred.GetNetworkCredential().password;} | convertto-json).tostring()
$cookie = (invoke-restmethod -contenttype "application/json" -method Post -uri "" -body $jsonPayload).RegistrationCookie

$jsonPayload = (@{lastCookie=$cookie;locale="en-US";preferredEventTypes=@(0,1)} | convertto-json).tostring()
$events = (invoke-restmethod -contenttype "application/json" -method Post -uri "" -body $jsonPayload)

Thank you in advance

October 23, 2017 at 7:22 pm

Try this:

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.