无法解析 Microsoft 图形的 url 字符串,因为使用了 Invoke-MSGraphRequest 命令和查询参数
Cannot parse url string for Microsoft graph because using the Invoke-MSGraphRequest command and query parameters
我无法使用当前的 URL 解析和调用,因为当我使用 $filter 和 $select 查询参数时,它会破坏字符串,但它在 Postman 中运行良好并给我我需要的所有数据。
Connect-MSGraph
Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/managedDevices?$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&$filter=(operatingSystem eq 'iOS')" -HttpMethod GET
我需要过滤这些设备,然后如果所有权是个人的,我将再次使用图 API 来使用 PATCH 更新对象设备。请帮忙解决这个问题
https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter
https://docs.microsoft.com/en-us/graph/api/intune-devices-manageddevice-get?view=graph-rest-1.0
您的问题的直接解决方案是简单地逐字转义 $
的反引号 `
:
Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/managedDevices?`$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&`$filter=(operatingSystem eq 'iOS')" -HttpMethod GET
或者使用 single-quotes '
来避免 PowerShell 试图扩展 看起来 的变量 - [=31 中的文字 single-quotes =] 必须通过 加倍 来转义它们:
Invoke-MSGraphRequest -Url 'https://graph.microsoft.com/beta/deviceManagement/managedDevices?$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&$filter=(operatingSystem eq ''iOS'')' -HttpMethod GET
也就是说,我个人建议从更简单的部分构建查询参数:
$endpointURL = 'https://graph.microsoft.com/beta/deviceManagement/managedDevices'
# assign variable parts of the filter to a variable
$targetOperatingSystem = 'iOS'
# construct a hashtable containing all the query parameters
$GraphParameters = [ordered]@{
'$select' = 'emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType'
'$filter' = "(operatingSystem eq '$targetOperatingSystem')"
}
# construct query string and final URL from the individual parts above
$queryString = $GraphParameters.GetEnumerator().ForEach({ $_.Key,$_.Value -join '=' }) -join '&'
$URL = $endpointURL,$queryString -join '?'
然后最后调用Invoke-MSGraphRequest -Url $URL -HttpMethod Get
我无法使用当前的 URL 解析和调用,因为当我使用 $filter 和 $select 查询参数时,它会破坏字符串,但它在 Postman 中运行良好并给我我需要的所有数据。
Connect-MSGraph
Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/managedDevices?$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&$filter=(operatingSystem eq 'iOS')" -HttpMethod GET
我需要过滤这些设备,然后如果所有权是个人的,我将再次使用图 API 来使用 PATCH 更新对象设备。请帮忙解决这个问题
https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter https://docs.microsoft.com/en-us/graph/api/intune-devices-manageddevice-get?view=graph-rest-1.0
您的问题的直接解决方案是简单地逐字转义 $
的反引号 `
:
Invoke-MSGraphRequest -Url "https://graph.microsoft.com/beta/deviceManagement/managedDevices?`$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&`$filter=(operatingSystem eq 'iOS')" -HttpMethod GET
或者使用 single-quotes '
来避免 PowerShell 试图扩展 看起来 的变量 - [=31 中的文字 single-quotes =] 必须通过 加倍 来转义它们:
Invoke-MSGraphRequest -Url 'https://graph.microsoft.com/beta/deviceManagement/managedDevices?$select=emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType&$filter=(operatingSystem eq ''iOS'')' -HttpMethod GET
也就是说,我个人建议从更简单的部分构建查询参数:
$endpointURL = 'https://graph.microsoft.com/beta/deviceManagement/managedDevices'
# assign variable parts of the filter to a variable
$targetOperatingSystem = 'iOS'
# construct a hashtable containing all the query parameters
$GraphParameters = [ordered]@{
'$select' = 'emailaddress,id,imei,operatingSystem,ownerType,managedDeviceOwnerType'
'$filter' = "(operatingSystem eq '$targetOperatingSystem')"
}
# construct query string and final URL from the individual parts above
$queryString = $GraphParameters.GetEnumerator().ForEach({ $_.Key,$_.Value -join '=' }) -join '&'
$URL = $endpointURL,$queryString -join '?'
然后最后调用Invoke-MSGraphRequest -Url $URL -HttpMethod Get