【问题标题】:Powershell script to pull Office 365 Reports through Microsoft Graphi API通过 Microsoft Graph API 提取 Office 365 报告的 Powershell 脚本
【发布时间】:2018-04-25 22:08:35
【问题描述】:

我正在尝试自动清理分配给我们用户的 Microsoft E3 许可证。

我一直在使用这篇文章作为初学者:https://blogs.technet.microsoft.com/dawiese/2017/04/15/get-office365-usage-reports-from-the-microsoft-graph-using-windows-powershell/

所以我在 Azure 中注册了应用程序并复制了重定向 URI 和应用程序 ID。

我还下载了最新的 msonline 模块,并使用 Azure 全局管理员作为 $cred。

我将脚本复制到 C:\Testing\ 中的服务器,然后在同一目录中创建了一个包含以下内容的脚本:

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

然后我得到这个错误:

Invoke-RestMethod : 远程服务器返回错误: (404) Not 成立。 在 C:\Temp\Get-Office365Report.ps1:333 char:15 + ... $result = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], 网络异常 + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodComm

这里的代码是:

$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

$uri的内容是:

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

所以$parameterset 是空的。不知道是不是这个原因?

任何帮助将不胜感激,谢谢!

最好的问候 卡斯珀

【问题讨论】:

    标签: powershell azure-ad-graph-api


    【解决方案1】:

    在脚本的 Q 和 A 中,解决方案已经发布。在脚本中替换 uri 行(我认为它在第 330 行左右):

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多