0

我无法使用 Invoke-restmethod 让特定的 API 调用在 powershell 中工作。专门传递 -d "\"\\RootFolder\New folder\"" 变量。用于移动设备组的 Curl API 命令示例:

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer Very long token" -d "\"\\\\RootFolder\\New folder\"" "https://SOTIServer.com:443/MobiControl/api/devicegroups/%255C%255CRootfolder%255COld%2520folder%255CSourceFolder/path"

到目前为止,我的 Powershell 调用不起作用:

$folderX="SourceFolder"

function MoveDir ([string]$Name, [string]$Token)
{
    $Path = "%255C%255CRootfolder%255COld%2520folder%255C" + $folderX
    $body = "\\\\RootFolder\\New Folder"
    $body = $body | ConvertTo-Json
    $MCFQDN = "https://SOTIServer.com:443"

    $Header2 = @{}
    $Header2["Authorization"] = "Bearer " + $Token

    try
    {
        $response2 = Invoke-restmethod -Uri https://$MCFQDN/mobicontrol/api/devicegroups/$Path/path -ContentType "application/json" -Method PUT -Body $body -Headers $Header2
    }
    catch
    {
        $($_.Exception.Message)
    }
}
4

0 回答 0