当我 运行 整个脚本时,powershell 命令不会 运行

powrshell command does not run when I run the entire script

我写了一个 ps1 脚本来自动安装一些软件包,但奇怪的是当我 运行 执行 SEP (Symantec Endpoint Protection) .exe 文件的命令片段时,它是执行得很好,但是当我执行整个脚本时,它执行 运行 命令片段。 我只是 运行 一个简单的 .exe 文件,即使我手动 运行 它也不会显示任何安装程序,而是在后台静默安装。 所以在脚本中,我只 运行ning .exe 文件,仅此而已。 我应该给出任何等待时间或任何其他输入吗?

Start-Process -Wait -FilePath "C:\Temp\Symantec-Windows\SEP 14.3.3384.1000 x64.exe" -passthru
$SymVersion = Get-WmiObject -Class Win32_Product -ComputerName $hostname | Where-Object -FilterScript {$_.Name -eq "symantec endpoint protection"} | Format-List -Property version, InstallState, name
echo $SymVersion
if($SymVersion)
{
echo 'Symantec is successfully installed' -ForegroundColor Green 
}
else
{
echo 'Symantec is not successfully installed' -ForegroundColor Red
}

赛门铁克防病毒 exe 文件是为静默安装而制作的。如果您想继续使用 GUI 模式,最好解压缩文件并使用带参数的 MSI 文件。使用您当前的脚本,最好检查进程是否以代码 0 退出。以下代码未经过测试。

$process = Start-Process -FilePath "C:\Temp\Symantec-Windows\SEP 14.3.3384.1000 x64.exe" -passthru -Wait
if($process.ExitCode -ne 0)
{
    throw "Installation process returned error code: $($process.ExitCode)"
} else { Write-Host "Installation Successful"}