我正在尝试创建一个Powershell脚本,以便将托管应用策略分配给一个组。所以我有一个函数Assign-ManagedAppPolicy,它采用Application polici id($ AppID)和JSON构造来表示POST请求的主体和应该分配的组的组ID。但我不断收到错误:
Assign-ManagedAppPolicy -AppID $AppID -JSON $GroupJS -GroupID $GroupID -Verbose
VERBOSE: POST https://graph.microsoft.com/Beta/managedAppPolicies/T_216bea0a-f02c-42ee-a0b3-8c0266d615bf/updateTargetedSecurityGroups with -1-byte payload`
回复内容:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'updateTargetedSecurityGroups'.",
"innerError": {
"request-id": "1a183b97-668b-41ca-9d97-dda6cd839249",
"date": "2017-05-25T15:45:37"
}
}
}
Assign-ManagedAppPolicy : Request to https://graph.microsoft.com/Beta/managedAppPolicies/T_216bea0a-f02c-42ee-a0b3-8c0266d615bf/updateTargetedSecurityGroups failed with HTTP Status BadRequest Bad Request
At line:1 char:1
+ Assign-ManagedAppPolicy -AppID $AppID -JSON $GroupJS -GroupID $GroupI ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Assign-ManagedAppPolicy
有什么猜测吗?
我的功能:
Function Assign-ManagedAppPolicy()
{
<#
.SYNOPSIS
This function is used to assign an Managed App policy using the Graph API REST interface
.DESCRIPTION`
The function connects to the Graph API Interface and assigns a Managed App policy
.EXAMPLE
Assign-ManagedAppPolicy -AppID $AppID -JSON $JSON
Assigns a Managed App policy in Intune
.NOTES
NAME: Assign-ManagedAppPolicy
#>
[cmdletbinding()]
param
(
$AppID,
$JSON,
$GroupID
)
$graphApiVersion = "Beta"
$Resource = "managedAppPolicies"
try {
if($AppID -eq "" -or $AppID -eq $null -or $JSON -eq "" -or $JSON -eq $null){
write-host "No Parameters specified, please specify valid AppID and GroupID for a Managed App Policy..." -f Red
}
else {
Test-JSON -JSON $JSON
$uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)/$($AppID)/updateTargetedSecurityGroups"
Invoke-RestMethod -Uri $uri -Headers $authToken -Method POST -Body $JSON -ContentType "application/json"
}
}
catch {
Write-Host
$ex = $_.Exception
$errorResponse = $ex.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($errorResponse)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
Write-Host "Response content:`n$responseBody" -f Red
Write-Error "Request to $Uri failed with HTTP Status $($ex.Response.StatusCode) $($ex.Response.StatusDescription)"
write-host
break
}
}
计划机构:
# Assign MAM Policy to group
$AppID
$GroupID
$GroupJS = @{"TargetedSecurityGroups"= ,@{"@odata.type"="#microsoft.graph.directoryObject";"id"=$($GroupID)}} | ConvertTo-Json