How to retrieve office 365 mailbox IDs using Invoke-RestMethod step by step

423 Views Asked by At

I'm developing a simple PowerShell script to retrieve office365 user mailbox folder IDs, my code fails at authentication stage displaying error 401 unauthorized. Is there a step that is missing so as to connect to office 365 mailbox using the Invoke-RestMethod cmdlet?

Below is the code

$cred = Get-Credential

Invoke-RestMethod -Uri "https://outlook.office.com/api/v1.0/me/MailFolders/" -Credential $cred | foreach-object{$_.value |select DisplayName,ID}

Error upon running the code. enter image description here

0

There are 0 best solutions below