0
votes

I'm trying to automate cleanup of assigned Microsoft E3 licenses to our users.

I've been using this article for starters: https://blogs.technet.microsoft.com/dawiese/2017/04/15/get-office365-usage-reports-from-the-microsoft-graph-using-windows-powershell/

So I registered the app in Azure and copied the Redirect URI along with the Application ID.

I also downloaded the latest msonline module and I'm using a Azure global admin as $cred.

I copied the script to a server in C:\Testing\ and then i made a script with the following content in the same directory:

.\Get-Office365Report.ps1 `
-TenantName "OurCompany.onmicrosoft.com" `
-ClientID "x00000x0-00x0-000x-x000-0000xx000x0x" `
-RedirectURI "urn:ReportingAPIAccess" `
-WorkLoad Tenant `
-ReportType getOffice365ActivationsUserDetail `
-Cred $cred `
-Verbose

However I then get this error:

Invoke-RestMethod : The remote server returned an error: (404) Not Found. At C:\Temp\Get-Office365Report.ps1:333 char:15 + ... $result = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodComm

and

The code here is:

$uri = "https://graph.microsoft.com/beta/reports/{0}({1})/content" -f $report, $parameterset
Write-Host $uri
Write-Host "Retrieving Report $report, please wait" -ForegroundColor Green
$result = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Get

and the content of $uri is:

https://graph.microsoft.com/beta/reports/getOffice365ActivationsUserDetail()/content

So $parameterset is empty. I'm unsure if it is the cause?

Any help would be greatly appreciated, thank you!

Best Regards Casper

1

1 Answers

0
votes

IN the Q and A for the script the solution had already been posted. In the script replace uri line (i think it was around line 330) with this:

$uri = "https://graph.microsoft.com/beta/reports/{0}({1})?`$format={2}" -f $report, $parameterset,'text/csv'