source

PowerShell에서 MsiExec 실행 및 반환 코드 가져오기

ittop 2023. 9. 9. 10:15
반응형

PowerShell에서 MsiExec 실행 및 반환 코드 가져오기

와 함께BAT/CMD간단하게 사용할 수 있는 스크립트"msiexec /i <whatever.msi> /quiet /norestart"그 다음에 확인합니다.%errorlevel%결과에 따라서

와 함께VBScript, 사용중Wscript.Shell물건Run()method, 나는 다음과 같은 결과를 얻을 수 있습니다.

"result = oShell.Run("msiexec /i ...", 1, True)"

PowerShell로 이 작업을 수행하려면 어떻게 해야 합니까?

저는 Start-Process에 그것을 마무리하고 결과 프로세스 객체의 ExitCode 속성을 사용할 것입니다.예를들면

(Start-Process -FilePath "msiexec.exe" -ArgumentList "<<whatever>>" -Wait -Passthru).ExitCode
$LastExitCode

아니면

$?

당신이 무엇을 추구하느냐에 따라.전자는 정수이고 후자는 부울 뿐입니다.더 나아가,$LastExitCode실행 중인 네이티브 프로그램에 대해서만 채워집니다.$?는 일반적으로 마지막 명령 실행이 성공했는지 여부를 알려주기 때문에 cmdlet에 대해서도 설정됩니다.

PS Home:\> cmd /c "echo foo"; $?,$LASTEXITCODE
foo
True
0
PS Home:\> cmd /c "ech foo"; $?,$LASTEXITCODE
'ech' is not recognized as an internal or external command,
operable program or batch file.
False
1

여러 가지를 제공하는 파워셸 앱 배포 키트를 사용할 수도 있습니다.

예를 들어 다음과 같이 사용할 수 있습니다.

Execute-MSI -Action 'Install' -Path "$dirFiles\your.msi" -AddParameters "INSTALLFOLDER=C:\$appFolder"

info http://psappdeploytoolkit.com/

언급URL : https://stackoverflow.com/questions/4124409/run-msiexec-from-powershell-and-get-return-code

반응형