I am trying to test if a DNS zone exists in Powershell using the following cmdlet:
Get-DNSServerZone abc.com
That works great, but what I need to do now is turn that into a True/False evaluation depending on if there was an error or if there was data returned.
For example, this is a TRUE scenario:
$a = Get-DnsServerZone abc.com
$a
ZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned
-------- -------- ------------- -------------- ------------------- --------
abc.com Secondary False False False
Whereas this is a FALSE scenario:
$a = Get-DnsServerZone def.com
Get-DnsServerZone : The zone def.com was not found on server DNSSERVER1.
At line:1 char:6
+ $a = Get-DnsServerZone def.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (def.com:root/Microsoft/...S_DnsServerZone) [Get-DnsServerZone], CimException
+ FullyQualifiedErrorId : WIN32 9601,Get-DnsServerZone
What I'm struggling with is how to evaluate on that? In layman's terms I need to check if $a
has actual data or not.
Many thanks!