我正在尝试使用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>
有人可以建议,如何实现这一目标?
提前致谢。
答案 0 :(得分:0)
我能够通过添加&#34; Set-Location&#34; C:\ Windows \ system32&#34;来修复脚本。作为第一线。所以我的脚本如下所示:
<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>