Powershell,如何更新几个dns记录

时间:2010-01-14 23:18:59

标签: powershell dns

我有以下脚本,但收到错误 -

脚本 -

$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 | Where-Object{$_.Ownername -match $CNAME}
Foreach($CNAME in $CNAMES)
{
  $Record.RecordData = "some.server.net"
  $Record.put()
}

错误 -

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

1 个答案:

答案 0 :(得分:0)

我没有尝试(因为我现在手头没有MS-DNS),但我怀疑你需要

$Record.PSBase.Put()

使其有效。

修改

看起来 $ Record 包含 System.Object 的数组,因此必须将其强制转换为适合访问 .RecordData .Put()

的类型

您的脚本会查询仅支持MicrossoftDNS_CNAMEType的<{3}}类型的记录。

我会尝试将$ Record发送给Get-Member

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

找出你正在处理的事情。