Installation
MSI
#Install MSI
Start-Process -NoNewWindow msiexec -argument "/I MyMSI.msi TRANSFORM=MYMSTFile.mst /qn /norestart" -Wait
| Switch | Explaination |
| /I | /I for Install |
| TRANSFORM | Call a transform file |
| /qn | Fully silent mode |
| /norestart | Do not restart the system after the installation |
EXE
#Install EXE
Start-Process -NoNewWindow -FilePath .\MySetup.exe "/MyEXEswitchs" -Wait
Uninstallation
#Get the application name
$GetSoftware0 = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -MATCH "MYSOFTWAREEXACTNAME" } | Select-Object -Property DisplayName, UninstallString
#Check if multiple application as the same name
ForEach ($Software in $GetSoftware0){
If ($Software.UninstallString){
$UninstallString = $Software.UninstallString cmd /c $UninstallString /quiet /norestart
}
}
Catch MSI exit code
(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode
Catch MSI exit code and manage return exit code
$ManageExitCode = (Start-Process -NoNewWindow msiexec -Argument "/I MyMSIPackage.msi REBOOT=ReallySuppress" -wait -PassThru).exitcode
if ($ManageExitCode -eq 0 -or $ManageExitCode -eq 3010)
{write-host "OK $ManageExitCode"
exit 0
}
else {
write-host "$ManageExitCode"
exit $ManageExitCode}