如何修改下面的代码,以便如果其中一个测试验证失败,它会退出循环并显示错误?
#Test the DNS server functionality, if no errors, generated from the below test, then all is good, exit script.
try
{
$testConnection = Test-Connection $domaincontroller -Count 1
If (($testConnection -ne "") -or ($testconnection -ne $null))
{
Test-DnsServer -IPAddress $ipV4
Test-DnsServer -IPAddress $ipV4 -Context Forwarder
Test-DnsServer -IPAddress $ipV4 -Context RootHints
Test-DnsServer -IPAddress $ipV4 -ZoneName $env:USERDOMAIN
}
else
{
Write-Host "$computername DNS test failed".
Exit
}
}
catch
{
Write-Output "Exception Type: $($_.Exception.GetType().FullName)"
Write-Output "Exception Message: $($_.Exception.Message)"
}