vendredi 8 mai 2020

Powershell wrong exit point from condition

I have this part of my code:

# Check how the kstart servers accessible
ping -n 1 sg-start-6001
$sgkstartcheck = $?

If($sgkstartcheck -ne 'True'){
$sgkstart = "10.104.170.250"
}
else {
$sgkstart = "sg-start-6001"
}

ping -n 1 am-start-4001.
$amkstartcheck = $?

If($amkstartcheck -ne 'True'){
$amkstart = "10.201.180.250"
}
else {
$amkstart = "am-start-4001"
}

ping -n 1 sh-start-8001
$shkstartcheck = $?

If($shkstartcheck -ne 'True'){
$shkstart = "10.113.170.250"
}
else {
$shkstart = "sh-start-8001"
}

ping -n 1 as-start-3001
$askstartcheck = $?

If($askstartcheck -ne 'True'){
$askstart = "10.46.160.250"
}
else {
$askstart = "as-start-3001"
}

ping -n 1 bk-start-1001
$bkkstartcheck = $?

If($bkkstartcheck -ne 'True'){
$bkkstart = "10.120.195.251"
}
else {
$bkkstart = "bk-start-1001"
}

$installfile = "windows/winlogbeat-6.2.4-windows-x86_64.zip"
$filebeatforwininstallfile = "windows/filebeat-6.2.4-windows-x86_64.zip"
$filename = "C:\winlogbeat-6.2.4-windows-x86_64.zip"
$filebeatfilename = "C:\filebeat-6.2.4-windows-x86_64.zip"
$webClient = New-Object System.Net.WebClient
$webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()

if($site -eq 'HKG1') {$webClient.DownloadFile("http://hk-rep-2001/$installfile",$filename)}
elseif($site -eq 'AMS4') {$webClient.DownloadFile("http://$amkstart/$installfile",$filename)}
elseif($site -eq 'SIN1' -or 'SIN3') {$webClient.DownloadFile("http://$sgkstart/$installfile",$filename)}
elseif($site -eq 'SHA1' -or 'SHA2') {$webClient.DownloadFile("http://$shkstart/$installfile",$filename)}
elseif($site -eq 'ASH1') {$webClient.DownloadFile("http://$askstart/$installfile",$filename)}
elseif($site -eq 'BKK1') {$webClient.DownloadFile("http://$bkkstart/$installfile",$filename)}

The site is ASH1.

Why the script tries the with the SIN value the download?

The site is ASH1, why it goes into the SIN elseif?

Seems like because in the ping test the sin is the first one and it is true, but it was installed couple of 10000 vms with this script and it just came :/

Aucun commentaire:

Enregistrer un commentaire