-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerhsell.ps1
52 lines (44 loc) · 1.69 KB
/
powerhsell.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
46
47
48
49
50
51
52
# Define the list of servers and the path to the Java executable
$servers = @("Server1", "Server2", "Server3")
$javaExecutablePath = "C:\path\to\your\java\executable.jar"
$destinationPath = "C$\Program Files\YourApp"
# Define SCCM details
$sccmSiteServer = "YourSCCMServer"
$sccmSiteCode = "YourSiteCode"
# Function to copy the Java executable to the remote server
function Copy-Executable {
param (
[string]$server,
[string]$sourcePath,
[string]$destPath
)
$session = New-PSSession -ComputerName $server
try {
Copy-Item -Path $sourcePath -Destination "\\$server\$destPath" -Recurse -Force
Write-Host "Copied executable to $server"
} catch {
Write-Host "Failed to copy executable to $server: $_"
} finally {
Remove-PSSession -Session $session
}
}
# Function to install the Java executable using SCCM
function Install-Executable {
param (
[string]$server,
[string]$executablePath
)
$installScript = @"
$SCCMPath = Get-WmiObject -Namespace "root\ccm" -Class SMS_Client
$exec = New-Object -ComObject wscript.shell
$exec.Run("java -jar $executablePath"), 0, $true
"@
Invoke-Command -ComputerName $server -ScriptBlock { param($script) Invoke-Expression $script } -ArgumentList $installScript
Write-Host "Installation command sent to $server"
}
# Loop through each server and deploy the Java executable
foreach ($server in $servers) {
Copy-Executable -server $server -sourcePath $javaExecutablePath -destPath $destinationPath
Install-Executable -server $server -executablePath "$destinationPath\executable.jar"
}
Write-Host "Deployment completed"