Kudu REST API Command endpoint error when executing powershell

后端 未结 3 1254
情书的邮戳
情书的邮戳 2021-01-25 01:46

When trying to execute the POST to /api/command according to this description the following error occurs:

PS C:\\> $Result.Error
remove-item : The Win32 int         


        
3条回答
  •  情话喂你
    2021-01-25 02:10

    I can't reproudce the issue that you mentioned. I test with following code,you could refer to it.

    $PublishingUsername = "`$userName"
    
    $publishingPassword = "password"
    
    $apiUrl = "https://webAppName.scm.azurewebsites.net/api/command"
    
    $json = @"
    {
        "command": 'powershell.exe -command `"get-childitem * -recurse | remove-item -force`"',
        "dir" : 'site\\wwwroot'
     }
    "@
    
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $PublishingUsername, $publishingPassword)))
    
    $Result = Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}  -Method Post -Body $json -ContentType "application/json"
    

    Test Result: I aslo check the kudu console that, all of the items under the folder site\wwwroot are deleted.

提交回复
热议问题