Virtual Machine Manager 2012 R2利用服务模板部署DC

服务模板作为VMM非常重要的一个功能,无论是在日常的应用虚机创建,还是在私有云中的自助申请,我们都需要先创建好各种的服务模板,管理员或者根据工作流再通过这些服务模板来完成我们对各种应用的自动化部署,所以服务模板都是一个关键所在,利用好服务模板,也是私有云迈出的第一步。下面就以全自动创建一台DC服务器为例,继续对服务模板进行介绍。

1、首先将下面脚本保存为PS文件,这个脚本将会对DC执行相应的配置。

$ScriptName = $MyInvocation.MyCommand.Name

if (($args.Count -le 1) -or ($args.Count -ge 4))

{

$Instructions = @"

usage: $ScriptName <Local Admin Password> <Domain Name> [Data Drive]

This script creates an Active Directory server

Required Paramaters:

<Local Admin Password>:

This is the same password used in the template configuration for local administrator.

<Domain Name>:

The domain used to create Active Directory and DNS trees.

Optional Parameters:

[Data Drive]

Optionally, the data drive for storing database, SYSVOL and log files can be entered.

"@

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("Script did not complete. $Instructions","Error", "1000")

exit

}

$pass = $args[0]

$domain = $args[1]

$driveLetter = $args[2]

$dataDrive = ""

$driveLetter = "C"

try{

# ToDo: Here we simply test if the drive letter entered as a param is actually a drive. This

# should be more agressive testing for writable and available free space using Get-PSDrive.

# Again for fast deploys we have control over we know attached drives and size but we

# are confirming here it exist and falling back if something went wrong attaching it.

if((New-Object System.IO.DriveInfo($driveLetter)).DriveType -ne 'NoRootDirectory')

{

$dataDrive = $driveLetter + ":\Windows\"

}

else

{

$dataDrive = "c:\Windows\"

}

$databasePath = $dataDrive + "NTDS"

$sysvolPath = $dataDrive + "SYSVOL"

Import-Module ADDSDeployment

$result = Install-ADDSForest `

-CreateDNSDelegation:$false `

-safemodeadministratorpassword (convertto-securestring $pass -asplaintext -force) `

-DatabasePath $databasePath `

-DomainMode "Win2012" `

-DomainName $domain `

-ForestMode "Win2012" `

-InstallDNS:$true `

-LogPath $databasePath `

-NoRebootOnCompletion:$false `

-SYSVOLPath $sysvolPath `

-force:$true

# Writing an event log entry

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("$result","Information", "1000")

}catch [Exception]{

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("Script failed. The error message: $_.Exception.Message","Error", "1000")

throw "$ScriptName failed to complete. $_.Exception.Message "

}

2、把脚本保存到库中

Virtual Machine Manager 2012 R2利用服务模板部署DC

3、打开VMM控制台,选择库,配置文件选项中选择应用程序配置文件,然后右键创建应用程序配置文件。

Virtual Machine Manager 2012 R2利用服务模板部署DC

4、在新建应用程序窗口中,填写名称。

Virtual Machine Manager 2012 R2利用服务模板部署DC

5、切换到应用程序设置,添加一个脚本类型为安装前的脚本,如下图,在可执行程序栏填入Powershell的路径,参数填写如下:

-noprofile Set-ExecutionPolicy RemoteSigned

Virtual Machine Manager 2012 R2利用服务模板部署DC

6、继续添加一个类型为安装前的脚本,脚本资源包选择刚才保存的PS脚本,并如下图进行配置,这里需要把超时修改为360秒,否则执行会失败。

Virtual Machine Manager 2012 R2利用服务模板部署DC

7、接下来在服务模板选项,选择创建服务模板

Virtual Machine Manager 2012 R2利用服务模板部署DC

8、创建一个单一计算机服务模板。

Virtual Machine Manager 2012 R2利用服务模板部署DC

9、把一个VM模板拖入到画布中,如下图。

Virtual Machine Manager 2012 R2利用服务模板部署DC

10、右键画布中的计算机层,属性,在OS配置中添加相应的DC服务和功能

Virtual Machine Manager 2012 R2利用服务模板部署DC

11、打开应用程序配置选项,在应用配置文件下拉选择刚才配置好的应用程序配置文件。

Virtual Machine Manager 2012 R2利用服务模板部署DC

12、完成后保存,并配置部署。

Virtual Machine Manager 2012 R2利用服务模板部署DC

13、为新服务实例进行配置,如下图。

Virtual Machine Manager 2012 R2利用服务模板部署DC

14、填入相关域信息,进行部署服务。

Virtual Machine Manager 2012 R2利用服务模板部署DC

15、如果在APP Controller中进行服务部署的话,体验会更好点。

Virtual Machine Manager 2012 R2利用服务模板部署DC

16、接下来就等待服务的运行完成了。这样,一台DC服务就完成创建了。

Virtual Machine Manager 2012 R2利用服务模板部署DC

















本文转自李珣51CTO博客,原文链接:http://blog.51cto.com/lixun/1324590 ,如需转载请自行联系原作者