【发布时间】: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