如何为Intune中的Win32应用添加第二个依赖项?
解决Intune Win32应用添加多个依赖项的问题
核心解决方案
不要切换到relationships接口,继续使用updaterelationships端点,但需采用全量更新的方式:每次调用时,将所有已存在的依赖项与新添加的依赖项一起传入请求体,而非仅传新依赖。
示例代码
假设已有一个依赖的targetId为$ID1,现在要添加第二个依赖$ID2,代码如下:
# 定义第一个依赖(保留已存在的配置) $Dependency1 = [ordered]@{ "@odata.type" = "#microsoft.graph.mobileAppDependency" "dependencyType" = "Detect" # 可根据需求改为autoInstall "targetId" = $ID1 } # 定义第二个新依赖 $Dependency2 = [ordered]@{ "@odata.type" = "#microsoft.graph.mobileAppDependency" "dependencyType" = "Detect" "targetId" = $ID2 } # 合并所有依赖到集合中 $Win32AppRelationships = [ordered]@{ "relationships" = @($Dependency1, $Dependency2) } # 调用updaterelationships接口执行全量更新 $uri = "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$ID/updaterelationships" Invoke-RestMethod -Uri $uri -Headers $authToken -Method Post -Body ($Win32AppRelationships | ConvertTo-Json -Depth 10) -ContentType "application/json"
关键说明
updaterelationships接口的设计逻辑是覆盖更新:传入的依赖集合会完全替换当前应用的所有依赖关系,因此必须包含所有需要保留的依赖项,不能仅传新增项。relationships接口仅支持GET请求(用于查询当前依赖),不支持POST创建依赖,这就是你触发"No method match route template"错误的原因。- 额外注意:使用
ConvertTo-Json时需加上-Depth 10参数,避免嵌套JSON结构被截断;调用前可先通过GET https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$ID/relationships获取现有依赖,再与新依赖合并,确保不丢失原有配置。
内容的提问来源于stack exchange,提问作者Max
相关产品推荐
相关产品推荐

