Hello,
I have a script to create an A-record in a zone and if the zone doesn't
exist it creates a zone as well. This is my script:
Param
( [String] $ZoneName = $(Throw "You must enter a zone name"),
[String] $RecordName = $(Throw "You must enter a record name"),
[string] $ip = $(Throw "You must enter an ip address")
)
$zone=get-wmiobject -namespace root\microsoftDNS -class MicrosoftDNS_Zone
-comp ZVW-MIRA -filter "name='$zonename'"
if (!$zone) {
$Type = 0
# AD Integration (only valid on Active Directory Domain Controllers)
$IsDSIntegrated = $False
# FileName (Optional and only valid for zones with AD integrated set to
$False)
# File must exist if specified and have size greater than 0b.
$Filename = $Null
# Master IP (Optional and only valid for Secondary, Stub and Forwarder zones)
$MasterIP = $Null
# AdminEmail (Optional and only valid for Primary zones, writes into SOA
record)
$AdminEmail = "domains.ordina.nl"
$NewZone =
([WMIClass]"\\ZVW-MIRA\root\MicrosoftDNS:MicrosoftDNS_Zone").CreateZone( `
$ZoneName, $Type, $IsDSIntegrated, $FileName, $MasterIP, $AdminEmail)
}
$rec = [WmiClass]"\\ZVW-MIRA\root\MicrosoftDNS:MicrosoftDNS_AType"
$rec | gm
$server = "ZVW-MIRA"
$class = 1
$ttl = 3660
$rec.CreateInstanceFromPropertyData($server, $ZoneName, $RecordName, $class,
$ttl, $ip)
It creates the zone and record correctly but it still gives this error:
Exception calling "CreateInstanceFromPropertyData" : "Generic failure "
At C:\dnsscript2.ps1:31 char:36
+ $rec.CreateInstanceFromPropertyData( <<<< $server, $ZoneName, $RecordName,
$class, $ttl, $ip)
Does anyone know what this means and what I can do? I'd prefer this error to
be gone.
I'm really new in the scripting so if you can give me the script with the
changes I can see what is different so I can understand it better.
Thanks in advance.


