替换
我想安装带有/q
开关的MSI,我在线查看,示例没有/q
Switch,我一直遇到错误。
我需要类似的东西:
$WorkingDirectory = (Split-Path $myinvocation.mycommand.path -Parent)
Start-Process -FilePath msiexec /i "$WorkingDirectoryLAPS.x64.msi" -ArgumentList /q
不要打扰Start-Process
。使用呼叫操作员:
& msiexec.exe /i "$WorkingDirectoryLAPS.x64.msi" /q
将整个命令放在括号中
示例(Python MSI):
Start-Process msiexec.exe -Wait -ArgumentList "/I $($LocalPython.FullName) /passive ALLUSERS=1 ADDLOCAL=Extensions"
用/q
/passive
并非所有安装程序都是相同的。要找到用于.msi的安装程序开关:
.LAPS.x64.msi /?
.LAPS.x64.msi -?
我还将msi
路径存储在变量中,并使用ArrayList
进行参数,类似的内容对我有用:
# Path to .msi
$msiPath= 'C:LAPS.x64.msi'
# Define arguments
[System.Collections.ArrayList]$arguments =
@("/i `"$msiPath`"",
"/quiet")
# Start installation
Start-Process -FilePath msiexec.exe -ArgumentList "$arguments" -Wait -NoNewWindow
$path="C:Datinstall.msi"
$parameters="/q"
$packageinstall=(split-path $path -leaf) + ' ' + $parameters
write-host $packageinstall
$computers = get-content c:com.txt
$computers | where{test-connection $_ -quiet -count 1} | ForEach-Object {
copy-item $path "\$_c$windowstemp" -Force -Recurse
$newProc=([WMICLASS]"\$_rootcimv2:win32_Process").Create("C:windowstemp$packageinstall")
If ($newProc.ReturnValue -eq 0) {
Write-Host $_ $newProc.ProcessId
} else {
write-host $_ Process create failed with $newProc.ReturnValue
}
}