This article shows how to remotely install MSI installer using PowerShell. I will explain how to install MSI on a local PC, and run the MSI for a remote PC using valid credentials using PowerShell step by step.
Install MSI on a local PC
Let’s start with a simpler case of installing an MSI on a PC with the Start-Process cmdlet. The Start-Process cmdlet starts a process defined in -FilePath on a local PC. For MSI installation, the -Wait parameter option was used to wait until the process ends.
Start-Process -FilePath msiexec.exe -ArgumentList '/i D:\node-v17.2.0-x64.msi /quiet /l D:\nodejsmsi.log' -Wait
Install MSI on a Remote PC
As an example, I will deploy the node js MSI installer to a remote PC and install the MSI silently.
Step 1: Get a User Credential with Get-Credential cmdlet that will be used for remote PC access with the privilege to install MSI. So as to run this step in an automated way, you can also export and import credentials with Get-Credential | Export-Clixml “storecredential.xml” and $Cred1 = Import-Clixml “storecredential.xml”
$Cred1 = Get-Credential
Step 2: Define RemotePC, target folder, and source MSI. Use Copy-Item cmdlet, perform copy MSI file to the target location.
$Cred1 = Get-Credential
$RemotePC = "PC1"
$targetDir = '\\' + $RemotePC +'\d$'
$sourceMSI = '\\Server\Share\node-v17.2.0-x64.msi'
Copy-Item -Path $sourceMSI -Destination $targetDir
Step 3: Invoke-Command cmdlet is used to run a command from a remote PC. ScriptBock part is the same as for local PC run.
$Cred1 = Get-Credential
$RemotePC = "PC1"
$targetDir = '\\' + $RemotePC +'\d$'
$sourceMSI = '\\Server\Share\node-v17.2.0-x64.msi'
Copy-Item -Path $sourceMSI -Destination $targetDir
Invoke-Command -ComputerName $RemotePC -Credential $Cred1 -ScriptBlock {
Start-Process -FilePath msiexec.exe -ArgumentList '/i D:\node-v17.2.0-x64.msi /quiet /l D:\nodejsmsi.log' -Wait
}
You may also be interested in the articles below:
How to Uninstall Application Remotely Using PowerShell
How to restore VM Snapshot remotely using PowerShell