如何通过 Rest-API 在 Airwatch/Workspace ONE 中设置设备名称(作为友好名称)
How to set the device name (as friendly name) in Airwatch/Workspace ONE via Rest-API
我希望通过 Rest-API 将 iOS 设备的设备名称和友好名称更改为不同的值。我可以这样更改友好名称:
$requestHeaders = @{
'Accept' = 'application/json'
'Authorization' = $auth
'aw-tenant-code' = $wsoApiKey
}
$body = @{
'DeviceFriendlyName' = $WsoDeviceName
}
$body = ConvertTo-Json $body
$uri = $wsoApiUri + $WsoDevice.Id.Value
Invoke-RestMethod -Uri $uri -ContentType "application/json; charset=utf-8" -Headers $requestHeaders -Body $body -Method Put
但我似乎无法找到更改设备名称的正确属性,无论是在本地 API 帮助(在服务器。local/api/help),还是在 vmwares 文档中。
发送 PUT 请求以更改 DeviceName 或 DeviceReportedName 显示没有任何更改。代码如下:
$body = @{
'DeviceName' = $WsoDeviceName
}
我知道可以通过 Web 界面将友好名称设置为设备名称。也许有一种方法可以通过 API 激活该选项,但我没有找到?在这种情况下,它将完成工作。
如果有人能指出正确的方向,我会很高兴。
此致
霍莱瓦施
我能够使用自定义 MDM 命令完成此操作。在下面的示例中,我在按设备序列号搜索时专门使用了 POST /devices/commands
方法。
$MdmCommandXml = [xml]@'
<dict>
<key>RequestType</key>
<string>Settings</string>
<key>Settings</key>
<array>
<dict>
<key>DeviceName</key>
<string></string>
<key>Item</key>
<string>DeviceName</string>
</dict>
</array>
</dict>
'@
$Auth = ""
$WsoApiKey = ""
$BaseUrl = "https://as<yourhostnumber>.awmdm.com/API/mdm"
$SerialNumber = ""
$Uri = "${BaseUrl}/devices/commands?command=CustomMdmCommand&searchBy=Serialnumber&id=${SerialNumber}"
$NewDeviceName = "NewDeviceName"
$MdmCommandXml.SelectSingleNode('//key[.="DeviceName"]/following-sibling::*[1]').InnerXml = $NewDeviceName
$RequestHeaders = @{
'Accept' = 'application/json'
'Authorization' = $Auth
'aw-tenant-code' = $WsoApiKey
}
$Body = @{
'CommandXml' = $MdmCommandXml.OuterXml
}
$Body = ConvertTo-Json $Body
Invoke-RestMethod -Uri $Uri -ContentType "application/json; charset=utf-8" -Headers $RequestHeaders -Body $Body -Method Post
我希望通过 Rest-API 将 iOS 设备的设备名称和友好名称更改为不同的值。我可以这样更改友好名称:
$requestHeaders = @{
'Accept' = 'application/json'
'Authorization' = $auth
'aw-tenant-code' = $wsoApiKey
}
$body = @{
'DeviceFriendlyName' = $WsoDeviceName
}
$body = ConvertTo-Json $body
$uri = $wsoApiUri + $WsoDevice.Id.Value
Invoke-RestMethod -Uri $uri -ContentType "application/json; charset=utf-8" -Headers $requestHeaders -Body $body -Method Put
但我似乎无法找到更改设备名称的正确属性,无论是在本地 API 帮助(在服务器。local/api/help),还是在 vmwares 文档中。 发送 PUT 请求以更改 DeviceName 或 DeviceReportedName 显示没有任何更改。代码如下:
$body = @{
'DeviceName' = $WsoDeviceName
}
我知道可以通过 Web 界面将友好名称设置为设备名称。也许有一种方法可以通过 API 激活该选项,但我没有找到?在这种情况下,它将完成工作。
如果有人能指出正确的方向,我会很高兴。
此致
霍莱瓦施
我能够使用自定义 MDM 命令完成此操作。在下面的示例中,我在按设备序列号搜索时专门使用了 POST /devices/commands
方法。
$MdmCommandXml = [xml]@'
<dict>
<key>RequestType</key>
<string>Settings</string>
<key>Settings</key>
<array>
<dict>
<key>DeviceName</key>
<string></string>
<key>Item</key>
<string>DeviceName</string>
</dict>
</array>
</dict>
'@
$Auth = ""
$WsoApiKey = ""
$BaseUrl = "https://as<yourhostnumber>.awmdm.com/API/mdm"
$SerialNumber = ""
$Uri = "${BaseUrl}/devices/commands?command=CustomMdmCommand&searchBy=Serialnumber&id=${SerialNumber}"
$NewDeviceName = "NewDeviceName"
$MdmCommandXml.SelectSingleNode('//key[.="DeviceName"]/following-sibling::*[1]').InnerXml = $NewDeviceName
$RequestHeaders = @{
'Accept' = 'application/json'
'Authorization' = $Auth
'aw-tenant-code' = $WsoApiKey
}
$Body = @{
'CommandXml' = $MdmCommandXml.OuterXml
}
$Body = ConvertTo-Json $Body
Invoke-RestMethod -Uri $Uri -ContentType "application/json; charset=utf-8" -Headers $RequestHeaders -Body $Body -Method Post