AWS EC2 安装 Chrome 作为用户数据

Rav*_*ngh 1 powershell amazon-ec2

我正在尝试在用户数据中使用 PowerShell 自动安装 Chrome 以及其他一些任务。但是 Chrome 安装失败,因为它需要处于提升模式的 PowerShell。

以下是我的代码片段:

<powershell>
#Change TimeZone
C:\Windows\System32\tzutil /s "AUS Eastern Standard Time"

#Install Chrome 
$Path = $env:TEMP;
$Installer = "chrome_installer.exe";
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile     $Path\$Installer; 
Start-Process -FilePath $Path\$Installer -ArgumentList "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path\$Installer

#Set Chrome as default browser
$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\" 
$chromeApp = "chrome.exe"
$chromeCommandArgs = "--make-default-browser"
& "$chromePath$chromeApp" $chromeCommandArgs
</powershell>
Run Code Online (Sandbox Code Playgroud)

有人可以建议一下,如何实现这一点吗?

提前致谢。

Rav*_*ngh 5

我可以通过添加“Set-Location”C:\Windows\system32" 作为第一行来修复脚本。所以我的脚本如下所示:

<powershell>
Set-Location "C:\Windows\system32"

#Change TimeZone
C:\Windows\System32\tzutil /s "AUS Eastern Standard Time"

#Install Chrome 
$Path = $env:TEMP;
$Installer = "chrome_installer.exe";
Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile     $Path\$Installer; 
Start-Process -FilePath $Path\$Installer -ArgumentList "/silent /install" -Verb RunAs -Wait;
Remove-Item $Path\$Installer

#Set Chrome as default browser
$chromePath = "${Env:ProgramFiles(x86)}\Google\Chrome\Application\" 
$chromeApp = "chrome.exe"
$chromeCommandArgs = "--make-default-browser"
& "$chromePath$chromeApp" $chromeCommandArgs
</powershell>
Run Code Online (Sandbox Code Playgroud)