Nested ifs are a mess
This commit is contained in:
parent
c483cbf687
commit
e1471191d4
@ -3,54 +3,54 @@ Function fDefaultGatewayCheck() {
|
|||||||
Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0' } | Sort-Object nexthop, metric1, interfaceindex
|
Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0' } | Sort-Object nexthop, metric1, interfaceindex
|
||||||
$vSCNextHop = (Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0' } | Sort-Object metric1 | select nexthop | Format-Wide | Out-String).trim()
|
$vSCNextHop = (Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0' } | Sort-Object metric1 | select nexthop | Format-Wide | Out-String).trim()
|
||||||
Test-Connection $vSCNextHop
|
Test-Connection $vSCNextHop
|
||||||
|
$vSCNextHopResult = $?
|
||||||
}
|
}
|
||||||
|
|
||||||
fDefaultGatewayCheck
|
fDefaultGatewayCheck
|
||||||
if ($? -eq $false)
|
|
||||||
{
|
Function fDNSResolutionCheck() {
|
||||||
Write-Host "SC-NET-ERR001: CANNOT PING DEFAULT GATEWAY"
|
Write-Host "---Testing DNS Resolution---"
|
||||||
Write-Host "Please check network connection"
|
Resolve-DnsName -Name "git.sdf.org"
|
||||||
Write-Host "If you would like to [F]orcefully continue, connect a keyboard and type F"
|
$vSCDNSResolutionTestResult1 = $?
|
||||||
Write-Host "If you would like to run this test [A]gain, connect a keyboard and type A"
|
Resolve-DnsName -Name "customresolutionutility.b-cdn.net"
|
||||||
$vSCNextHopUserResponse = Read-Host "F / A?"
|
$vSCDNSResolutionTestResult2 = $?
|
||||||
if ($vSCNextHopUserResponse -contains "A")
|
Resolve-DnsName -Name "github.com"
|
||||||
{
|
$vSCDNSResolutionTestResult3 = $?
|
||||||
fDefaultGatewayCheck
|
Resolve-DnsName -Name "www.ultimarc.com"
|
||||||
}
|
$vSCDNSResolutionTestResult4 = $?
|
||||||
else
|
Resolve-DnsName -Name "www.autohotkey.com"
|
||||||
{
|
$vSCDNSResolutionTestResult5 = $?
|
||||||
fDNSResolutionCheck
|
Resolve-DnsName -Name "eternallybored.org"
|
||||||
}
|
$vSCDNSResolutionTestResult6 = $?
|
||||||
}
|
Resolve-DnsName -Name "7-zip.org"
|
||||||
else
|
$vSCDNSResolutionTestResult7 = $?
|
||||||
|
$vSCDNSResolutionTestResultArray = @($vSCDNSResolutionTestResult1,$vSCDNSResolutionTestResult2,$vSCDNSResolutionTestResult3,$vSCDNSResolutionTestResult4,$vSCDNSResolutionTestResult5,$vSCDNSResolutionTestResult6,$vSCDNSResolutionTestResult7)
|
||||||
|
}
|
||||||
|
|
||||||
|
fDNSResolutionCheck
|
||||||
|
|
||||||
|
if ($vSCNextHopResult -contains $false)
|
||||||
|
{
|
||||||
|
Write-Host "SC-NET-ERR001: CANNOT PING DEFAULT GATEWAY"
|
||||||
|
Write-Host "Please check network connection"
|
||||||
|
Write-Host "If you would like to [F]orcefully continue, connect a keyboard and type F"
|
||||||
|
Write-Host "If you would like to run this test [A]gain, connect a keyboard and type A"
|
||||||
|
$vSCNextHopUserResponse = Read-Host "F / A?"
|
||||||
|
if ($vSCNextHopUserResponse -contains "A")
|
||||||
{
|
{
|
||||||
Function fDNSResolutionCheck() {
|
fDefaultGatewayCheck
|
||||||
Write-Host "---Testing DNS Resolution---"
|
|
||||||
Resolve-DnsName -Name "git.sdf.org"
|
|
||||||
$vSCDNSResolutionTestResult1 = $?
|
|
||||||
Resolve-DnsName -Name "customresolutionutility.b-cdn.net"
|
|
||||||
$vSCDNSResolutionTestResult2 = $?
|
|
||||||
Resolve-DnsName -Name "github.com"
|
|
||||||
$vSCDNSResolutionTestResult3 = $?
|
|
||||||
Resolve-DnsName -Name "www.ultimarc.com"
|
|
||||||
$vSCDNSResolutionTestResult4 = $?
|
|
||||||
Resolve-DnsName -Name "www.autohotkey.com"
|
|
||||||
$vSCDNSResolutionTestResult5 = $?
|
|
||||||
Resolve-DnsName -Name "eternallybored.org"
|
|
||||||
$vSCDNSResolutionTestResult6 = $?
|
|
||||||
Resolve-DnsName -Name "7-zip.org"
|
|
||||||
$vSCDNSResolutionTestResult7 = $?
|
|
||||||
$vSCDNSResolutionTestResultArray = @($vSCDNSResolutionTestResult1,$vSCDNSResolutionTestResult2,$vSCDNSResolutionTestResult3,$vSCDNSResolutionTestResult4,$vSCDNSResolutionTestResult5,$vSCDNSResolutionTestResult6,$vSCDNSResolutionTestResult7)
|
|
||||||
if ($vSCDNSResolutionTestResultArray -contains $false)
|
|
||||||
{
|
|
||||||
Write-Host "SC-NET-ERR002: CANNOT RESOLVE DNS"
|
|
||||||
Write-Host "Please check your DNS server. Sweetcade cannot continue with a broken DNS server."
|
|
||||||
Write-Host "This script will now exit in 60 seconds."
|
|
||||||
Start-Sleep -Seconds 60
|
|
||||||
Exit 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Exit 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($vSCDNSResolutionTestResultArray -contains $false)
|
||||||
|
{
|
||||||
|
Write-Host "SC-NET-ERR002: CANNOT RESOLVE DNS"
|
||||||
|
Write-Host "Please check your DNS server. Sweetcade cannot continue with a broken DNS server."
|
||||||
|
Write-Host "This script will now exit in 60 seconds."
|
||||||
|
Start-Sleep -Seconds 60
|
||||||
|
Exit 1
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Exit 0
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user