exception - Try/Catch Add-DnsServerResourceRecordA in PowerShell -
i want catch exception occurs, when adding dns record add-dnsserverresourcerecorda
in powershell switch -createptr
, no reverse lookupzone exists.
there no error. if provoke error simple menu pops , informs me situation. independent -erroraction
switch $error
variable not receive error. what's fault?
thanks reply.
ps c:\users\xyz>> add-dnsserverresourcerecorda -name "test-mwi4" -ipv4address 1.1.1.1 -createptr -zonename contoso.biz -erroraction continue add-dnsserverresourcerecorda : failed create ptr record. resource record test-mwi4 in zone mn-man.biz on server mndemucdc010 created successfully, corresponding ptr record not created. @ line:1 char:1 + add-dnsserverresourcerecorda -name "test-mwi4" -ipv4address 1.1.1.1 -createptr - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : notspecified: (test-mwi4:root/microsoft/...resourcerecorda) [add-dnsserverresourcerecorda], cimexception + fullyqualifiederrorid : win32 9715,add-dnsserverresourcerecorda
thank you!
in order use command in try catch block use below code:
try { add-dnsserverresourcerecorda -name "test-mwi4" -ipv4address 1.1.1.1 -createptr -zonename contoso.biz -erroraction stop } catch { write-host "error while adding pointer record:`n$($error[0].exception.message)" }
$error[0]
returns:
$error[0] add-dnsserverresourcerecorda : failed zone information contoso.biz on server hydlpt487. @ line:3 char:5 + add-dnsserverresourcerecorda -name "test-mwi4" -ipv4address 1.1.1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : notspecified: (test-mwi4:root/microsoft/...resou rcerecorda) [add-dnsserverresourcerecorda], cimexception + fullyqualifiederrorid : win32 1722,add-dnsserverresourcerecorda
Comments
Post a Comment