powershell - PowerShell脚本查找文件然后启动引用它的命令?
问题描述
我正在尝试在 PowerShell 中编写一个脚本,该脚本将在文件夹中搜索特定的 msi 文件(子文件夹位置会有所不同),然后运行引用该文件和其他位于同一目录中的文件的安装命令。这将是一个工具,我们的 L1 帮助台人员可以使用它来运行通过 SCCM 分配的软件的安装,可能使用与 SCCM 运行的不同的命令行变量。
尝试了不同的代码组合,无法安装应用程序。
这在查找软件时效果很好
Get-ChildItem -Path C:\Windows\ccmcache -Recurse -Filter softwarename.msi
ForEach 部分不起作用
$Path = Get-ChildItem -Path C:\Windows\CCMCache -Recurse -Filter Something.MSI
ForEach ( $Installer in ( Get-ChildItem -Path $Path.DirectoryName -Filter *.MSI ) ) {
Start-Process -Wait -FilePath C:\windows\system32\msiexec.exe -ArgumentList "/i $Installer.FullName"
}
我基本上想做这样的事情,使用找到 msi 文件的目录进行安装:
msiexec /i 软件名.msi /q /norestart
解决方案
我看到的唯一错误是你通常不能在不添加 $() 的情况下引用字符串中对象的属性:
Start-Process -Wait -FilePath C:\windows\system32\msiexec.exe -ArgumentList "/i $($Installer.FullName)"
为什么不直接运行 msiexec?
msiexec /i $installer.fullname
推荐阅读
- firebase - 如何在 Firebase 中使用 503 代码创建维护页面?
- php - VS代码调试php
- javascript - p5js 图像数组
- android - 如何每 60 秒运行一次计划任务?
- python - 使用 django 的 test_forms 给出 AssertionError
- php - 如何通过codeigniter中的url传递多个变量?
- jquery - 除了标题之外添加描述块到放大的弹出窗口所见即所得 v14
- python - Vs代码自动缩进不适用于python
- java - 如何打印 javafx 窗格?
- php - Laravel 中的 YEAR(begin_date) 未知列