1

其中 BRIVWTDC2 是我的 DC

$rec = [WmiClass]"\\BRIVWTDC2\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
$rec | get-member -membertype method

给我:

   TypeName: System.Management.ManagementClass#ROOT\MicrosoftDNS\MicrosoftDNS_ResourceRecord

Name                                 MemberType Definition
----                                 ---------- ----------
CreateInstanceFromTextRepresentation Method     System.Management.ManagementBaseObject CreateInstanceFromTextRepresentation(System.String DnsServe...
GetObjectByTextRepresentation        Method     System.Management.ManagementBaseObject GetObjectByTextRepresentation(System.String DnsServerName, ...

$rec.CreateInstanceFromTextRepresentation

给我:

PS C:\Windows\system32> $rec.CreateInstanceFromTextRepresentation


MemberType          : Method
OverloadDefinitions : {System.Management.ManagementBaseObject CreateInstanceFromTextRepresentation(System.String DnsServerName, System.String Contain
                      erName, System.String TextRepresentation)}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : System.Management.ManagementBaseObject CreateInstanceFromTextRepresentation(System.String DnsServerName, System.String Containe
                      rName, System.String TextRepresentation)
Name                : CreateInstanceFromTextRepresentation
IsInstance          : True

那为什么我不能

$rec.CreateInstanceFromTextRepresentation("BRIVWTDC2", "stage.testdmc.com", "SECARC in CNAME BRIVWTARC2.stage.testdmc.com")

其中 arg 是 DC,arg 2 是区域,arg 3 是文本表示 = 让我成为 RIVWTARC2.stage.testdmc.com 的别名 SECARC

我只是得到:

Exception calling "CreateInstanceFromTextRepresentation" : "Generic failure "
At line:1 char:42
+ $rec.CreateInstanceFromTextRepresentation <<<< ("BRIVWTDC2", "stage.testdmc.com", "'SECARC' in CNAME 'BRIVWTARC2.stage.testdmc.com'")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WMIMethodException

这说明我在做一些根本上愚蠢的事情......

帮助

4

3 回答 3

1

SECARC需要是 FQDNSECARC.stage.testdmc.com

于 2012-08-30T15:55:30.737 回答
0

看起来您在 . 上缺少第四个输出参数CreateInstanceFromTextRepresentation. 尝试:

$rr = $null
$rec.CreateInstanceFromTextRepresentation("BRIVWTDC2", 
                                          "stage.testdmc.com", 
                                          "SECARC in CNAME BRIVWTARC2.stage.testdmc.com", 
                                          [ref] $rr )

您可能必须将其实例$rr化为 MicrosoftDNS_ResourceRecord 的实例。我不知道该怎么做。

于 2012-06-14T14:43:21.230 回答
0

这是权限,我们需要是可以更改 DNS 的人( Heads and Brick Walls :-( ) 以下示例创建 DNS 别名,必须以管理员或可以更改 DNS 的用户身份运行

# DnsChanger.ps1
# Change the DNS Entries for Arbitrary Servers
# version 0.1 15/08/2012
# Paddy Carroll 
# 2 arguments (1) physical server name (2) server alias
# 

# setup event source

if (! [System.Diagnostics.EventLog]::SourceExists("DnsManager"))
{
"Administrative script to create event source has not been run: DnsManager.ps1"
# which is just [System.Diagnostics.EventLog]::CreateEventSource("DnsManager", "Application")
throw 'error'
}

# initialise event

$evt=new-object System.Diagnostics.EventLog("Application")
$evt.Source="DnsManager"
$errevent=[System.Diagnostics.EventLogEntryType]::error
$infoevent=[System.Diagnostics.EventLogEntryType]::information


# set up variables

$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name  

# get arguments

if($args.count -lt 2)
{
   "Script requires two parameters, a physical server name and an alias. FDQN names will be truncated and the current domain will be appended"
   $evt.WriteEntry("Wrong number of arguments supplied to DnsManager " ,$errevent,2)
   throw 'error'
}

$phys = $args[0].split('.')[0]
$alias = $args[1].split('.')[0]
$filter = "ContainerName = " + [char]34 + $domain + [char]34 

$filter

# test for existence of CNAMEType alias

try{
   $rec = Get-WmiObject -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_CNAMEType -filter $filter
   if (!$rec)
      {
    # if it doesnt exist, get all AType aliases
         $rec = Get-WmiObject -Namespace 'root\MicrosoftDNS' -Class MicrosoftDNS_AType -    filter $filter
      }
   }catch{
      $type = $_.Exception.getType().FullName
      $detail = $_.Exception.ErrorDetails().toString()
      $evt.WriteEntry("Problem getting DNS Namespace for " + $domain  ,$errevent,3)
      throw 'error'
   }


# create the alias

try{
$rec[0].CreateInstanceFromTextRepresentation($domain,$domain,$alias + '.' + $domain + ' IN     CNAME ' + $phys + '.'+$domain)
}catch{
    $type = $_.Exception.getType().FullName
    $detail = $_.Exception.ErrorDetails().toString()
    $evt.WriteEntry("Problem creating Alias for " + $phys + " as " + $alias + " : " +    $type + " : " + $detail,$errevent,1)
    throw 'error'
   }
$evt.WriteEntry("Alias created for " + $phys + " as " + $alias ,$infoevent,1)
于 2012-08-22T17:40:25.913 回答