-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall-RemoteMSI.ps1
45 lines (44 loc) · 1.72 KB
/
Install-RemoteMSI.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Param(
[cmdletbinding()]
[Parameter(
Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true
)
]
[Alias('ComputerName')]
[string[]]$Name,
[Parameter(
Mandatory=$true,
Position=1
)
]
[string]$InstallerPath
)
$InstallFilePath = (get-childitem $InstallerPath).directoryName
$InstallFile = (get-childitem $InstallerPath).name
foreach ($computer in $Name){
Write-Output "Installing: $InstallFilePath\$installFile to $Computer"
if(test-wsman $Computer -ErrorAction Ignore){
Write-Verbose "Begin Copy Block"
Write-Verbose "Begin $InstallFile copy"
if (-not (test-path "\\$($Computer)\c$\Windows\Patches\" )){
new-item "\\$($Computer)\c$\Windows\Patches\" -ItemType Directory
}
copy-item "$InstallFilePath\$InstallFile" "\\$($Computer)\c$\Windows\Patches\" -Force
Write-Verbose "$InstallFile copied"
Write-Verbose "End Copy Block"
Write-Verbose "Being Invoke-Command Block"
Write-Verbose "Target PC = $Computer"
invoke-command -computerName $Computer -ScriptBlock {
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList /i, "C:\Windows\Patches\$($args[0])", /qn, /norestart -wait
get-eventlog -LogName application -newest 1 -InstanceId 1033 | select-object message
} -ArgumentList (,$InstallFile)
Write-Verbose "Invoke-Command Block completed"
Write-Output "Deployment Complete"
Remove-Item "\\$Computer\c$\Windows\Patches\$InstallFile"
}else{
write-warning -Message "unable to connect to WinRM @ $($computer)"
}
}