Skip to content

Instantly share code, notes, and snippets.

@MVKozlov
Created October 12, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MVKozlov/d7f32171d640904630bfe10d40d7ea18 to your computer and use it in GitHub Desktop.
Save MVKozlov/d7f32171d640904630bfe10d40d7ea18 to your computer and use it in GitHub Desktop.
Install MSI Remotely
<#
.SYNOPSIS
Install MSI package by copy-run-remove
.DESCRIPTION
Install MSI package by copy-run-remove
.PARAMETER ComputerName
Remote computer name
.PARAMETER MSI
Path to msi package
.NOTES
Author: Max Kozlov
Name: Install-MSI
.LINK
https://gist.github.com/MVKozlov/d7f32171d640904630bfe10d40d7ea18
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline, Position=0, Mandatory=$true)]
[string[]]$ComputerName,
[Parameter(Position=1, Mandatory=$true)]
[string[]]$MSI
)
BEGIN {
function InstallMSI($comp, $MSI) {
if (-not (Test-WSMan $comp -ErrorAction SilentlyContinue)) {
Write-Error "Can't Connect to $comp"
return
}
foreach ($package in $MSI) {
$MSIName = Split-Path -Path $package -Leaf
$remote = '\\{0}\c$\{1}' -f $comp, $MSIName
Copy-Item $package $remote
Write-Information "$($comp): Invoke install $MSIname"
$result = Invoke-Command -ComputerName $comp { cmd /c start /wait msiexec /quiet /norestart /i C:\$using:MSIName; $? }
Remove-Item -Path $remote -Force -ErrorAction Continue
[PSCustomObject]@{
ComputerName = $comp
MSIName = $MSIName
Result = $result
FullPath = $package
}
}
}
}
PROCESS {
foreach ($comp in $ComputerName) {
InstallMSI $comp $MSI
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment