Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 具有合作伙伴凭据的MS Graph API访问客户端租户_Powershell_Office365_Microsoft Graph Api - Fatal编程技术网

Powershell 具有合作伙伴凭据的MS Graph API访问客户端租户

Powershell 具有合作伙伴凭据的MS Graph API访问客户端租户,powershell,office365,microsoft-graph-api,Powershell,Office365,Microsoft Graph Api,我使用以下PowerShell代码访问MS Graph API Import-Module MSOnline $User = "UserName" $Password = "Password" $TenantName = "tenantname.onmicrosoft.com" $clientId = "clientId" $authority = "https://login.microsoftonline.com/$TenantName" $authContext = New-Object

我使用以下PowerShell代码访问MS Graph API

Import-Module MSOnline
$User = "UserName"
$Password = "Password"
$TenantName = "tenantname.onmicrosoft.com"
$clientId = "clientId"
$authority = "https://login.microsoftonline.com/$TenantName"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$AADCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" -ArgumentList $AdminUser, $Password
$resourceAppIdURI = "https://graph.microsoft.com"
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$AADCredential)

$authHeader = @{
    'Content-Type'='application\json'
    'Authorization'=$authResult.CreateAuthorizationHeader()
}
$uri = "https://graph.microsoft.com/beta/$TenantName/reports/getEmailActivityUserDetail(period='D7')"
Invoke-RestMethod -Uri $uri -Method Get -Headers $authHeader
当用户和租户同意时,它可以正常工作。我想做的是使用具有委托权限的管理员访问我们的客户租户。我已将应用程序设置为具有预先同意权限,根据,该权限还应允许我追求的行为。但是,当我使用合作伙伴管理员凭据和客户端租户名称运行代码时,我收到一个400错误请求错误。我在这里遗漏了什么步骤?

根据(请参阅主题开头的重要说明),对于CSP预同意,只有Microsoft Graph中的目录和Intune资源支持合作伙伴模型。随着时间的推移,更多的资源将支持partner/CSP模型。如果这对您很重要,请在上为此创建请求

希望这有帮助,

您好,似乎是用户或管理员授予了权限。