TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Reply
 
LinkBack Thread Tools Display Modes
Old 26-06-2008, 04:29 PM   #1
voodooking
Guest
 
Posts: n/a
programmatically change dns a record

i have a need (HA FAILOVER) to programmatically change a servers ip address
in it's a record.
fields to be changed would be
IPAddress
RecordData
TextRepresentation
theoretically script would look like this
###################
$changeip = Get-WmiObject -ComputerName DNSSERVER namespace
"root\microsoftdns" -class MICROSOFTDNS_ATYPE | where {$_.Ownername -match
"servername.domain"}
$changeip.IPAddress = "xxx.xxx.xxx.xxx"
$changeip.RecordData = "xxx.xxx.xxx.xxx"
$changeip.TextRepresentation = "servername.domain IN A xxx.xxx.xxx.xxx"

$changeip.put()
###################
any reason that this should/shouldn't work ??

  Reply With Quote
Old 26-06-2008, 04:29 PM   #2
Shay Levi
Guest
 
Posts: n/a
Re: programmatically change dns a record

Hi voodooking,


It creates a new host record rather then updating it. Try to use the modify()
method instead:

$a = Get-WmiObject -ComputerName DNSSERVER -namespace "root\microsoftdns"
-class MICROSOFTDNS_ATYPE -filter "OwnerName='shayTest.domain.com'"

# Modify(System.UInt32 TTL, System.String IPAddress)}
$a.modify($null,"xxx.xxx.xxx.xxx")


Note that the query can return multiple host records, in that case use foreach.


---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

v> i have a need (HA FAILOVER) to programmatically change a servers ip
v> address
v> in it's a record.
v> fields to be changed would be
v> IPAddress
v> RecordData
v> TextRepresentation
v> theoretically script would look like this
v> ###################
v> $changeip = Get-WmiObject -ComputerName DNSSERVER namespace
v> "root\microsoftdns" -class MICROSOFTDNS_ATYPE | where {$_.Ownername
v> -match
v> "servername.domain"}
v> $changeip.IPAddress = "xxx.xxx.xxx.xxx"
v> $changeip.RecordData = "xxx.xxx.xxx.xxx"
v> $changeip.TextRepresentation = "servername.domain IN A
v> xxx.xxx.xxx.xxx"
v> $changeip.put()
v> ###################
v> any reason that this should/shouldn't work ??


  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 05:26 PM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional