我正在尝试通过powershell在一台远程机器上安装google chrome。这就是我想要做的(我几乎是从不同网站上的一些其他帖子中拼凑而来的):
$Path = $env:TEMP;
$Installer = "chrome_installer.exe";
(new-object System.Net.WebClient).DownloadFile('http://dl.google.com/chrome/install/375.126/chrome_installer.exe', "$Path\$Installer");
Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path\$Installer
在第四行失败了:Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait;
出现以下错误:
Start-Process : This command cannot be run due to the error: The handle is
invalid.
At line:1 char:2
+ Start-Process -FilePath $Path\$Installer -Args "/silent /install" -V ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand
我对PowerShell非常缺乏经验,我很难弄清楚错误中的“句柄”是什么。如有任何帮助,我们将非常感谢:)
EDIT:在失败的命令周围加上一个try/catch { $_ | FL * -Force}
的,它会给出以下输出:
PSMessageDetails :
Exception : System.InvalidOperationException: This command cannot
be run due to the error: The handle is invalid.
at System.Management.Automation.MshCommandRuntime.Th
rowTerminatingError(ErrorRecord errorRecord)
TargetObject :
CategoryInfo : InvalidOperation: (:) [Start-Process],
InvalidOperationException
FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands
.StartProcessCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 4
PipelineIterationInfo : {}
相反,通过捕获$_.Exception,它提供了:
Message : This command cannot be run due to the error: The handle is
invalid.
Data : {}
InnerException :
TargetSite : Void ThrowTerminatingError(System.Management.Automation.ErrorR
ecord)
StackTrace : at System.Management.Automation.MshCommandRuntime.ThrowTerm
inatingError(ErrorRecord errorRecord)
HelpLink :
Source : System.Management.Automation
HResult : -2146233079
发布于 2018-06-12 05:27:28
据我所知,这归结于这样一个事实:在Azure Web App环境中,您没有权限自由安装应用程序。
我猜环境的管理是受限制的,所以他们可以保证一定的服务水平。
你可以在这里了解更多:
https://docs.microsoft.com/en-us/azure/app-service/choose-web-site-cloud-service-vm
发布于 2018-06-06 04:04:20
尝试用双引号将提供给启动进程命令的进程引起来,或者使用$(Join-Path $Path $Installer)
现在,您正在为$Installer转义$,因此无法解析文件的路径。
Start-Process -FilePath "$Path\$Installer" -Args "/silent /install" -Verb RunAs -Wait;
# OR (even better I think)
Start-Process -FilePath $(Join-Path $Path $Installer) -Args "/silent /install" -Verb RunAs -Wait;
https://stackoverflow.com/questions/50707140
复制相似问题