powershell - 使用 Powershell 从列表中安装软件
问题描述
我正在构建一个脚本来自动化计算机构建和配置:这个想法是 WDS 尽可能干净,自动运行这个脚本,它将检查序列号,查询我们的 Workday 资产数据库并根据什么配置操作系统分配给该系统需求的用户。
现在我专注于 3 个大组:笔记本电脑、台式机和实验室。所有 3 将有一些 SW 将是相同的,一些将是特定的。我的问题是 msiexec:最初,我对每个组的所有安装进行了硬编码。但这意味着每次更新某些内容时我都必须更改脚本(例如默认推出一个新应用程序)。这并不理想。
function Install-Desktop {
#Write-Output "Here will be the install Desktop computer script"
$IPATH="<Path To root sw folder>"
#Software List
<# SOFTWARE LIST #>
$office="$IPATH\script\o365"
$webex="$IPATH\script\webex"
$chrome="$IPATH\script\chrome"
#install Ofice:
Invoke-Expression "$office\setup.exe /configure $office\O365.xml"
$params = '/i', "$webex\webexapp.msi",'/qb!','/norestart'
Start-Process msiexec -ArgumentList "$params" -Wait -PassThru
$params = '/i', "$chrome\GoogleChromeStandaloneEnterprise64.msi",'/qb!','/norestart'
Start-Process msiexec -ArgumentList $params -Wait -PassThru
}
这段代码运行良好。
现在我的想法是从列表中导入要安装的软件(维护列表比每次修改脚本更容易)。就像是:
function install-software {
param (
[String]$Type
)
$IPATH=<ROOT SW Folder>
$SoftWares=Import-Csv -Path "$IPath\script\$Type`.csv" #there will be a Laptop.csv in that path
foreach ($Software in $SoftWares) {
#detect if it is msiexect or other:
# (this has to do with how the csv is built, the first parameter is '/i' if it is an msi installer)
if ($Software.param1 -eq "'/i'") {
Start-Process msiexec -ArgumentList $Software -Wait -PassThru
}
else {
$Params=[string]::Join(" ",$Software.param1,$Software.param2,$Software.param3,$Software.param4)
Invoke-Expression "$Params"
}
}
}
这仅适用于其他部分。但是在 if 的 msiexec 端,MSI 打开时不带参数。我尝试了很多方法来传递参数,但都没有奏效。无论如何,我都不是 PowerShell 专家,所以我可能在这里缺少一些东西。
解决方案
好吧,看起来你必须通过完整路径,它甚至不允许你使用挂载的网络驱动器:所以答案在 csv 上。而不是 S:\<安装程序的路径> 它必须是 \<安装程序的完整路径> 并且我还必须去掉所有的引号和双引号。
推荐阅读
- android - 找到多个文件,其独立于操作系统的路径 'META-INF/androidx.legacy_legacy-support-core-utils.version' (java)
- html - 在一行CSS中放置一个带圆圈的矩形
- vue.js - Vuex mapActions:映射器参数必须是数组或对象
- angular - ASP.NET Core + Angular 使用 Azure DevOps 发布管道部署工件
- gulp - 错误:src 路径的 glob 参数无效,用作变量
- haskell - 为什么 Monoidal 和 Applicative 定律告诉我们同样的事情?
- java - 如何在不同时区的某个时间执行作业
- mysql - 坚持基于三个表获取行
- codec - LibAOM软件部分功能中的“facade”是什么意思
- java - 使用 Java 8 和谓词基于 Id 将三个异构列表合并为单个列表