【发布时间】:2020-12-17 20:38:06
【问题描述】:
我正在尝试使用以下 cmdlet 测试 Powershell 中是否存在 DNS 区域:
Get-DNSServerZone abc.com
这很好用,但我现在需要做的是根据是否存在错误或是否返回数据将其转换为真/假评估。
例如,这是一个真实的场景:
$a = Get-DnsServerZone abc.com
$a
ZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned
-------- -------- ------------- -------------- ------------------- --------
abc.com Secondary False False False
这是一个错误的场景:
$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
我正在苦苦挣扎的是如何评估它?用外行的话来说,我需要检查$a 是否有实际数据。
非常感谢!
【问题讨论】:
标签: powershell