もうすっかり古いはなしになるのですが、9月28日、MSC 2012 で SC-006 セッションにご参加くださった皆様、ありがとうございました。
冒頭で、Windows Server 2012 で構築した仮想ドメインコントローラーを Windows PowerShell を使用してクローンするデモを行いました。
その際に使用したスクリプトを掲載します。
(公開されている資料に書かれているものに若干不具合がございました…すみません)
それにしても、たったこれだけのスクリプトでDCが複製できてしまうなんて….Hyper-V 2012 + New AD すてきです。
スクリプトの実行環境は以下の通りです。(ITCAMP-FS は Hyper-V ホストです)
スクリプトの解説は以下をご参照ください。
仮想化した DC を PowerShell で複製する http://www.slideshare.net/junichia/dc-powershell
スクリプトは以下からダウンロードできます(大したもんじゃないですが…)
スクリプトのダウンロード http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-56-58/8233.CloneDC.ps1
$SourceDC = "ITCAMP-DC02"
$DistDC = "ITCAMP-DC03"
$distPDCEmu = "ITCAMP-DC01"
$SourceHyperVHost = "ITCAMP-FS"
$DistHyperVHost = "ITCAMP-FS"
$VMStore = "\\$DistHyperVHost\VMStore"
$ConfirmPreference = "none"
Move-ADDirectoryServerOperationMasterRole -Identity $distPDCEmu -OperationMasterRole PDCEmulator
Get-ADComputer $SourceDC | %{Add-ADGroupMember -Identity "Cloneable Domain Controllers" -Members $_.samAccountName}
Invoke-Command -ComputerName $SourceDC -ScriptBlock { Get-ADDCCloningExcludedApplicationList -GenerateXml -Force }
Invoke-Command -ComputerName $SourceDC -ScriptBlock { `
New-ADDCCloneConfigFile -Static -IPv4Address "192.168.210.52" ` -IPv4DNSResolver "192.168.210.50" ` -IPv4SubnetMask "255.255.255.0" ` -IPv4DefaultGateway "192.168.210.254" ` -CloneComputerName "$Args" ` -SiteName "Default-First-Site-Name" } ` -ArgumentList $DistDC
Stop-VM -ComputerName $SourceHyperVHost -Name $SourceDC
Get-VM -ComputerName $SourceHyperVHost -Name $SourceDC | %{ Export-VM $_ -Path $VMStore}
Start-VM -ComputerName $SourceHyperVHost -Name $SourceDC
$CFG = (Dir "$VMStore\$SourceDC\Virtual Machines\*.xml").FullName
MD \\$DistHyperVHost\F$\$DistDC
Import-VM -ComputerName $DistHyperVHost -Path $CFG -GenerateNewId -Copy-VhdDestinationPath F:\$DistDC
Get-VM -ComputerName $DistHyperVHost -Name $SourceDC |Where-Object {$_.State -EQ "Off"} | Rename-VM -NewName $DistDC
Start-VM -ComputerName $DistHyperVHost -Name $DistDC