Powershell,如何更新多个dns记录

发布于 2024-08-17 13:08:18 字数 1056 浏览 2 评论 0 原文

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

脚本 -

$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

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 | 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷途知返 2024-08-24 13:08:18

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

$Record.PSBase.Put()

才能使其正常工作。

编辑:

因为它看起来$Record包含一个System.Object数组,所以会有将其转换为合适的类型以访问 .RecordData.Put()

您的脚本查询类型的记录仅支持 CreateInstanceFromPropertyData

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

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

以了解您正在处理什么。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文