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はゾーン、arg3はテキスト表現です=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

SECARCFQDNである必要がありますSECARC.stage.testdmc.com

于 2012-08-30T15:55:30.737 に答える
0

の4番目のパラメータが欠落しているようですCreateInstanceFromTextRepresentation。試す:

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

$rrMicrosoftDNS_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 に答える