powershell - 通过 Powershell 使用自定义安装路径和组件静默安装 Visual Studio 的参数
问题描述
Powershell 的新手,并尝试编写一个脚本,该脚本可以使用 Invoke-Command 及其 -ScriptBlock 参数使用自定义安装路径和自定义组件在远程服务器上进行 Visual Studio 2017 的静默安装。能够静默安装 Visual Studio,但不提供安装路径和自定义组件列表,因为我不确定如何为 thsoe 传递参数。尝试了各种 没有任何帮助,具体到这个任何地方。
参数 (
$session = "New-PSSession -ComputerName $server -Credential $mycredentials",
$SourceFile = "\\server\D$\Somefolder\vs.exe",
$Destination = "D:\Somefolder\"
)
Write-Host "Installing Visual Studio"
Copy-Item -FromSession $session -Path $SourceFile -Destination $destination -Force
Invoke-Command -Session $session -ScriptBlock { Start-Process $Destination\vs.exe -ArgumentList '--quiet', '--installPath "C\VS\"' -Wait
}
Exit-PSSession
尝试了安装路径的不同变体,例如 --installPath "D:\Somefolder\", -installPath "D:\Somefolder\", -install 'D:\Somefolder\' ,甚至考虑过通过变量传递参数但不确定如何它会在这种情况下工作吗?此后降落在这里没有成功,甚至在任何地方都没有看到针对这种情况的帮助。
解决方案
尝试类似以下(未经测试) - 请注意与您尝试的内容相关的评论:
param (
# Use $(...) to use a command's output as a parameter default value.
# By contrast assigning "..." only assigns a *string*.
$session = $(New-PSSession -ComputerName $server -Credential $mycredentials),
# To be safe, better to `-escape $ inside "..." if it's meant to be a literal.
$SourceFile = "\\server\D`$\Somefolder\vs.exe",
$Destination = "D:\Somefolder"
)
Write-Host "Installing Visual Studio"
Copy-Item -FromSession $session -Path $SourceFile -Destination $destination -Force
# You don't need the session anymore now that you've copied the file.
# Normally you'd call
# Remove-PSSession $session
# However, given that the session may have been passed as an argument, the caller
# may still need it.
# With the installer present on the local machine, you can invoke
# Start-Process locally - no need for a session.
Start-Process -Wait $Destination\vs.exe -ArgumentList '--quiet', '--installPath "C:\VS"'
# No need for Exit-PSSession (which is a no-op here), given that
# you haven't used Enter-PSSession.
推荐阅读
- python - 弹性搜索无法获取 python 代码中的所有文档
- c++ - 如何转换 std::bitset
到 std::bitset ? - python-3.x - 为什么我的 Python 代码不能将一个数字的所有除数打印出来?
- css - NativeScript 中的 GridLayout 无法正确显示
- c - 有没有办法在 HEALPIx C 库中找到像素的顶点?
- typescript - 理解特定 TypeScript 索引签名的含义
- sql - teradata 中的存储过程
- python - 将 .txt 文件输入到 .exe 文件中
- javascript - 遍历表时如何忽略空值(仅限Javascript)
- events - 如何在 Purescript Halogen 中实现诸如自动增量计数器之类的东西