开发者

Powershell, how to update several dns records

开发者 https://www.devze.com 2022-12-16 05:44 出处:网络
I have the following script, but am getting an error - Script - $CNAMES = Get-Content \"C:\\Temp\\alias.txt\"

I have the following script, but am getting an error -

Script -

$CNAMES = Get-Content "C:\Temp\alias.txt"
$Query = "Select * from MicrosoftDNS_CNAMEType"
$Record = Get-WmiObject -Namespace "root\microsoftdns" -Query $Query -ComputerName 10.10.10.1 |开发者_C百科 Where-Object{$_.Ownername -match $CNAME}
Foreach($CNAME in $CNAMES)
{
  $Record.RecordData = "some.server.net"
  $Record.put()
}

Error -

Property 'RecordData' cannot be found on this object; make sure it exists and is settable.
At C:\temp\DNSUpdateCNAMETarget_02.ps1:7 char:9
+ $Record. <<<< RecordData = "some.server.net"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Method invocation failed because [System.Object[]] doesn't contain a method named 'put'.
At C:\temp\DNSUpdateCNAMETarget_02.ps1:8 char:12
+ $Record.put <<<< ()
    + CategoryInfo          : InvalidOperation: (put:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

TIA


I didn't try (cause i don't have a MS-DNS at hand right now) but i'd suspect that you need

$Record.PSBase.Put()

to make it work.

EDIT:

As it looks $Record holds an array of System.Object so will have to cast it a suitable type to access .RecordData and .Put()

Your script queries for records of type MicrossoftDNS_CNAMEType which only support CreateInstanceFromPropertyData.

I would try sending you $Record to Get-Member

Get-WmiObject -Namespace "root\microsoftdns" -Query $Query -ComputerName 10.10.10.1 | Get-Member

to find out, what you are dealing with.

0

精彩评论

暂无评论...
验证码 换一张
取 消