执行Powershell时Kudu REST API命令端点错误 [英] Kudu REST API Command endpoint error when executing powershell
问题描述
当尝试根据
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屋!