当尝试根据 /api/command 执行 POST 时这个描述 https://github.com/projectkudu/kudu/wiki/REST-API#command出现以下错误:
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 脚本片段:
$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
to SilentlyContinue
没有多大帮助。
我无法重现你提到的问题。我用下面的代码进行了测试,你可以参考一下。
$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"
测试结果:我还检查了 kudu 控制台,发现文件夹 site\wwwroot 下的所有项目都已删除。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)