-
Notifications
You must be signed in to change notification settings - Fork 31
/
ExampleUsage.ps1
39 lines (33 loc) · 1.33 KB
/
ExampleUsage.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
param (
[Parameter(Mandatory)]
[string[]]$Client,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$InstallerFilePath,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$ModuleFolderPath = 'C:\Program Files\WindowsPowerShell\Modules\PSSoftware'
)
foreach ($c in $Client) {
try {
## Perform numerous connection checks before copying everything over
$failReason = "The client [$($c)] "
if (-not (Test-Connection -ComputerName $c -Quiet -Count 1)) {
throw "$failReason cannot be pinged"
} elseif (-not (Test-Path "\\$c\c$")) {
throw "$failReason 's admin share is unavailable"
}
## Copy the installer to the client
Copy-Item -Path $InstallerFilePath -Destination "\\$c\c$"
## Copy the PSSoftware module to the client
Copy-Item -Path $ModuleFolderPath -Destination "\\$c\c$" -Recurse
## Execute the software installer
Invoke-Command -ComputerName $c -ScriptBlock {
Import-Module C:\PSSoftware\PSSoftware.psm1
$installerFileName = $using:InstallerFilePath | Split-Path -Leaf
Install-Software -OtherInstallerFilePath "C:\$installerFileName" -OtherInstallerArgs '/silent /norestart'
}
} catch {
Write-Error -Message $_.Exception.Message
}
}