-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.ps1
More file actions
55 lines (44 loc) · 1.71 KB
/
Copy pathScript.ps1
File metadata and controls
55 lines (44 loc) · 1.71 KB
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
53
54
55
param(
[string]$username,
[string]$password
)
$WarningPreference = 'SilentlyContinue'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username, $securePassword)
$computerName1 = "192.168.1.12"
$computerName2 = "192.168.1.13"
$scriptBlock = {
$ActiveNode = (Get-ClusterGroup | Where-Object { $_.Name -eq "ca-dbd28c5d-2c62-49a3-8751-ae6936c604e5" }).OwnerNode.ToString()
$hostname = hostname
if ($hostname -eq $ActiveNode) {Get-akshciupdates}
else { Write-Output "Node Inactive" }
}
$maxAttempts = 3 # Numero massimo di tentativi
$attempt = 0
function Invoke-RemoteCommand {
param(
[string]$computerName,
[scriptblock]$scriptBlock,
[pscredential]$cred
)
$result = $null
$success = $false
while (-not $success -and ($attempt -lt $maxAttempts)) {
$attempt++
try {
$result = Invoke-Command -ComputerName $computerName -ScriptBlock $scriptBlock -Credential $cred -ErrorAction Stop
$success = $true
} catch {
Write-Output "Tentativo $attempt fallito su $computerName. Riprovo..."
}
}
if (-not $result) {
$result = "No Updates Available"
}
return $result
}
$Host1 = Invoke-RemoteCommand -computerName $computerName1 -scriptBlock $scriptBlock -cred $cred
$Host2 = Invoke-RemoteCommand -computerName $computerName2 -scriptBlock $scriptBlock -cred $cred
Write-output "Host1: $Host1" | out-file -filepath C:\temp\updateresult.txt -append
Write-output "----------------" | out-file -filepath C:\temp\updateresult.txt -append
Write-output "Host2: $Host2" | out-file -filepath C:\temp\updateresult.txt -append