Install MSI File Remotely

I recently asked to find a way to deploy SolarWinds agent to about 200 servers. As I’m familiar with PowerShell, I wrote a short script below to install the agent remotely from my workstation.

# List of servers
$computers = get-content C:\Servers.txt

# Source installation files
$installFileMSI = "\\share\SolarWinds\SolarWinds-Agent\SolarWinds-Agent.msi"
$installFileMST = "\\share\SolarWinds\SolarWinds-Agent\SolarWinds-Agent.mst"

foreach($computer in $computers)
$destinationFolder = "\\$computer\C$\Temp"

# Create the C:\Temp folder on remote server if not exist
if(!(Test-Path -Path $destinationFolder))
New-Item $destinationFolder -ItemType Directory
# Copy the installation files to the remote server
Copy-Item -Path $installFileMSI -Destination $destinationFolder -Force
Copy-Item -Path $installFileMST -Destination $destinationFolder -Force

# Run the installation
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process msiexec.exe -ArgumentList '/i C:\Temp\SolarWinds-Agent.msi TRANSFORMS=C:\Temp\SolarWinds-Agent.mst /q /norestart' -Wait}

# Wait for the installation to fully finish
Timeout /t 15 /nobreak

# Remove the C:\Temp folder on the remote server
Remove-Item -Path $destinationFolder -Recurse -Force
Write-Host $_.Exception.Message


Leave a Reply

Your email address will not be published. Required fields are marked *