0

Hello I can't install file.msi in PowerShell on the remote computer. I can copy file.msi to remote computer but this job isn't execute. This one-liner working only when PowerShell is running like a admin:

Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock {
   Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Users\file.msi", '/passive'}
}
2
  • 1
    Try to add -Wait to Start-Process as shown in here: stackoverflow.com/questions/25407353/…. If won't work, there is another trick I can post Commented Apr 23, 2021 at 12:23
  • -Wait is not working Commented May 11, 2021 at 9:09

1 Answer 1

1

Following approach should work to be used as scripblock, you will need to find a way for your package to perform the $logcheck, either event log or a file. This sample had MS Office unistall.

Note, if you are planning to run it on large number of workstations/regularly I would suggest to replace while($true) with finite for loop or timelapse.

I have also placed your execution script as is, but for me msiexec.exe worked without need to do PowerShell

$scriptUninstallApp = {
  Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Users\file.msi", '/passive'}
  $logcheck = ""
  while($true)
  {   
    if($logcheck -match "Windows Installer removed the product")
    {
      return
    }
    else
    {
      start-sleep -Seconds 1
      [string]$logcheck = get-eventlog -logname application -newest 10 -Source msiinstaller | ?{$_.message -like "*Windows Installer removed the product. Product Name: Microsoft Office*"} | select -ExpandProperty message
    }
  }
}

Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock $scriptUninstallApp
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.