繁体   English   中英

无法从 PowerShell 脚本安装 Visual Studio

[英]Cannot install Visual Studio from PowerShell script

我正在尝试通过 PowerShell 安装 Visual Studio,在本地计算机上运行良好,但是当我在我们的 AWS Windows Server 2012R2 上运行它时,我不断收到错误消息。 我在下面附上了我的代码和错误。 谢谢

PowerShell脚本

错误

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$here = pwd
$software = "Microsoft Visual Studio Installer";
$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $software }) -ne $null



#If VSCode was not installed before, it will be download required files and install it.

If(-Not $installed)

{

Write-Host "'$software' is NOT installed.";

wget https://aka.ms/vs/17/release/vs_community.exe -outfile “vs.exe”

.\vs.exe install --quiet --norestart

}
#If VSCode was installed before, it will try to update it to the newer version, if available.

#If no updates available, it will do nothing.

else

{

Write-Host "'$software' is installed."

if ( Test-Path -Path $here\vs.exe )

{

.\vs.exe update --quiet --norestart

}

else {

wget https://aka.ms/vs/17/release/vs_community.exe -outfile "vs.exe"

.\vs.exe update --quiet --norestart

}

}

您使用了选项-outfile vs.exe但这不是您告诉wget重命名下载文件的方式。 这实际上是以下内容:

  1. 将文件下载到vs_community.exe (因为这是原始 URL 中的文件名)
  2. 将日志文件写入utfile
  3. 忽略vs.exe参数

将下载的内容定向到命名文件的 wget 选项实际上是-O ,而不是-outfile (相当于-o utfile ,它将日志写入utfile )。

要指定正确的输出文件名,请使用:

-O vs.exe

或者干脆执行wget https://aka.ms/vs/17/release/vs_community.exe然后执行下载的文件,名为vs_community.exe

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM