Created
October 12, 2017 07:15
-
-
Save MVKozlov/d7f32171d640904630bfe10d40d7ea18 to your computer and use it in GitHub Desktop.
Install MSI Remotely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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