我正在尝试使用 PowerShell 无提示脚本安装一个客户端软件。下面是我创建的脚本,它不起作用并抛出如下错误:
无法验证参数“ArgumentList”上的参数。参数为 null、空或参数集合的元素包含 null 值。提供一个不包含任何空值的集合,然后重试该命令
下面的行是正确的还是有任何错误,我在这里遇到问题。
$Args = @("/S", "/L1033", -INSTALL_TYPE=PRESERVE_VERSION, START_MENU=AStartMenuFolder\Software\production\)
完整脚本:
$INSTALLDIR = "C:\Software\Software.exe"
$Args = @("/S", "/L1033", -INSTALL_TYPE=PRESERVE_VERSION, START_MENU=AStartMenuFolder\Software\production\)
$logfile = "D:\BACKUP\Install_Logfile.txt"
$ErrorActionPreference = 'Stop'
try {
$exitcode = (Start-Process $Installer -ArgumentList $Args -NoNewWindow -Wait -Passthru).ExitCode
if ($exitcode -eq 0) {
[System.Windows.MessageBox]::Show('Installation Completed Successfully')
} else {
[System.Windows.MessageBox]::Show('Installation Failled')
}
} catch {
"$_" | Out-File $logfile -Append
{[System.Windows.MessageBox]::Show('Installation Failled')}
}
Edit:
$Installer = "C:\OTE\OTE.exe"
$params = @("/S", "/L1033", "-INSTALL_TYPE=PRESERVE_VERSION", "-START_MENU=AStartMenuFolder\OTE\production\")
$logfile = "C:\Install_Logfile.txt"
$ErrorActionPreference = 'Stop'
& $Installer @params
if ($LastExitCode -eq 0) {
[Windows.MessageBox]::Show('Installation Completed Successfully')
} else {
"$_" | out-file $logfile -append
[Windows.MessageBox]::Show('Installation Failled')
}
在上面的脚本中我收到如下错误,
无法验证参数“ArgumentList”上的参数。参数为 null、空或参数集合的元素包含 null 值。提供一个不包含任何空值的集合,然后重试该命令。