%20%EC%84%A4%EC%B9%98%EC%9D%98%20%EC%84%B1%EA%B3%B5%20%EC%97%AC%EB%B6%80%EB%A5%BC%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%97%90%EC%84%9C%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%ED%99%95%EC%9D%B8%ED%95%A0%20%EC%88%98%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
저는 매우 많은 수의 MSP 업데이트( .msp
확장명이 있는 파일, Windows Installer를 통해 배포됨)를 차례로 설치하기 위해 PowerShell 스크립트(아래 참조)를 작성했습니다. 이제 MSP 업데이트 설치가 실패한 경우에도 이 스크립트를 통해 알려주고 싶습니다.
내가 시도한 것: 오류 코드 쿼리.두 가지 접근 방식이 있습니다.
- 하나는 직접 실행한 후 $LASTEXITCODE를 사용하여 오류 코드를 얻는 것입니다
MSIEXEC.EXE
. 지루하다. 다른 하나는
-PassThru
에 스위치를 추가하고Start-Process
그 결과를 객체에 저장하고 를$a
사용하여 오류 코드를 읽는 것과 관련이 있습니다$a.ExitCode
. 이와 같이:$a=Start-Process msiexec.exe -ArgumentList "/p `"$MspRelPath`" /log `"$LogRelPath`" /passive /norestart" -Wait -PassThru Write-Host $a.ExitCode
둘 다 유용하지 않습니다. msiexec.exe
종료 코드로 항상 0을 반환하는 것 같습니다 .
누구든지 관심이 있는 경우 스크립트는 다음과 같습니다.
param (
[parameter(mandatory=$false)][Switch]$BypassAdminPrompt
)
Try
{
Clear-Host
# Get script name
$ScriptFileObject=(Get-Item $PSCommandPath)
$ScriptName=$ScriptFileObject.Name
$ScriptPath=$ScriptFileObject.DirectoryName
# Load Windows Forms and initialize visual styles
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Application]::EnableVisualStyles()
# Is the script holding administrative privileges?
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
if ($IsAdmin -eq $false) {
if (!$BypassAdminPrompt) {
Start-Process powershell.exe -ArgumentList "-ExecutionPolicy $env:PSExecutionPolicyPreference -File `"$PSCommandPath`" -BypassAdminPrompt" -Verb RunAs
} else {
$result=[System.Windows.Forms.MessageBox]::Show("This script requires administrative privileges, which are absent.", $ScriptName, "OK", "Error");
}
break;
}
# Install...
Set-Location $ScriptPath
$MSP_list = Get-ChildItem *.msp -Recurse
if ($MSP_list -eq $null) {
$result=[System.Windows.Forms.MessageBox]::Show("Nothing found to install.`rSearch path was "+$ScriptPath, $ScriptName, "OK", "Error");
}
else
{
$MSP_list | ForEach-Object {
# Ordinarily, I'd pass the path in the form of ".\foldername\filename.msp" but Windows Installer does not accept that.
# It must be in "foldername\filename.msp" form.
$MspRelPath = $_.FullName.Substring($ScriptPath.Length+1)
$LogRelPath = $MspRelPath+".log"
Write-Host $MspRelPath
Start-Process msiexec.exe -ArgumentList "/p `"$MspRelPath`" /log `"$LogRelPath`" /passive /norestart" -Wait
}
Remove-Variable MspRelPath
Remove-Variable LogRelPath
Pause
}
Remove-Variable MSP_list
}
Catch
{
$result=[System.Windows.Forms.MessageBox]::Show("Error!`r`r"+$Error[0], $ScriptName, "OK", "Error");
break;
}
답변1
MSIExec 이벤트에 대한 Windows 이벤트를 확인하거나 완료되면 로그 출력 내용을 가져와 실패 표시를 확인하십시오.
MSIExec을 사용하여 원격으로 MSI를 설치하고 MSIExec이 종료될 때까지(또는 프로세스/서비스가 시작될 때까지) 기다리는 스크립트가 있습니다. 일반적인 설치 시간 이후에 아무 일도 일어나지 않으면 MSIExec 호출에 포함된 로그 경로를 확인하고 실패 또는 성공 메시지 확인