执行Powershell时Kudu REST API命令端点错误 [英] Kudu REST API Command endpoint error when executing powershell

查看:51
本文介绍了执行Powershell时Kudu REST API命令端点错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试根据此说明发生以下错误:

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 internal error "The handle is invalid" 0x6 occurred 
while getting the console mode. Contact Microsoft Customer Support Services.
At line:1 char:44
+ get-childitem * -recurse | remove-item -force
+                                            ~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Remove-Item], HostExce 
   ption
    + FullyQualifiedErrorId : GetConsoleMode,Microsoft.PowerShell.Commands.Rem 
   oveItemCommand

我用来执行此操作的POSH脚本片段:

The piece of POSH script I'm using to perform this operation:

$json = @"
{
    "command": 'powershell.exe -command `"get-childitem * -recurse | remove-item -force`"',
    "dir" : 'site\\wwwroot',
 }
"@

$kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/command"

$progressPreference = "silentlyContinue"

$Result = Invoke-RestMethod -Uri $kuduApiUrl `
                        -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
                        -Body $json `
                        -Method POST `
                        -ContentType "application/json"

我发现很多博客都指出这与交互式控制台输出有关,但是,将 $ ProgressPreference 设置为 SilentlyContinue 并没有多大帮助.

I've found a lot of blogs specifying this is related to the interactive console output, however, setting $ProgressPreference to SilentlyContinue hadn't helped a lot.

推荐答案

github 正确的POSH命令应为:

After checking this issue on github the correct POSH command should be:

get-childitem -recurse |remove-item -recurse -force

直接从Kudu控制台甚至是REST API/api/命令端点执行时,效果很好

It works well when executing directly from Kudu console or even REST API /api/command endpoint

这篇关于执行Powershell时Kudu REST API命令端点错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆