![](/img/trans.png)
[英]Passing arguments as a variable when installing an MSI using Start-Process
[英]Install msi using Start-Process with /q switch?
我想安装一个带/q
开关的msi,我在网上查看,这些示例没有/q
开关,并且不断出错。
我需要类似的东西:
$WorkingDirectory = (Split-Path $myinvocation.mycommand.path -Parent)
Start-Process -FilePath msiexec /i "$WorkingDirectory\LAPS.x64.msi" -ArgumentList /q
不要为Start-Process
烦恼。 使用呼叫运算子 :
& msiexec.exe /i "$WorkingDirectory\LAPS.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:\Dat\install.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$\windows\temp" -Force -Recurse
$newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create("C:\windows\temp\$packageinstall")
If ($newProc.ReturnValue -eq 0) {
Write-Host $_ $newProc.ProcessId
} else {
write-host $_ Process create failed with $newProc.ReturnValue
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.