Skip to content

Instantly share code, notes, and snippets.

@junichia
Created March 29, 2017 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junichia/804dddd094247169dcf08946726d8b19 to your computer and use it in GitHub Desktop.
Save junichia/804dddd094247169dcf08946726d8b19 to your computer and use it in GitHub Desktop.
Configuration CreateNewADForest {
# このスクリプトはDSCにアップロードする。ただし、コンパイルはPowerShellから行う。
param
(
## [Parameter(Mandatory)]
## [string] $CustomerNumber
)
Import-DscResource -ModuleName xActiveDirectory -ModuleVersion 2.16.0.0
Import-DscResource -ModuleName xNetworking -ModuleVersion 3.2.0.0
Import-DscResource -ModuleName xPendingReboot -ModuleVersion 0.3.0.0
#$DomainCreds = Get-AzureRmAutomationCredential -ResourceGroupName "rm-pharaojp" -AutomationAccountName "automationaccount2" -Name "cloudadmin"
#$userCred = Get-AzureRmAutomationCredential -ResourceGroupName "rm-pharaojp" -AutomationAccountName "automationaccount2" -Name "user01"
$DomainCreds = Get-AutomationPSCredential -Name "cloudadmin"
$UserCreds = Get-AutomationPSCredential -Name "user01"
$RetryCount=20
$RetryIntervalSec=30
$ComputerName = $env:COMPUTERNAME
##ComputerNameの下五桁が顧客番号
$CustomerNumber = $ComputerName.Substring($ComputerName.Length -5, 5)
$DomainName = "ocms" + $CustomerNumber + ".com"
Node localhost
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
WindowsFeature DNS
{
Ensure = "Present"
Name = "DNS"
}
xDnsServerAddress DnsServerAddress
{
Address = '10.0.0.4'
InterfaceAlias = 'イーサネット 2'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]DNS"
}
WindowsFeature RSAT-AD-Tools
{
Name = 'RSAT-AD-Tools'
Ensure = 'Present'
}
WindowsFeature RSAT-ADDS
{
Name = 'RSAT-ADDS'
Ensure = 'Present'
}
WindowsFeature RSAT-AD-AdminCenter
{
Name = 'RSAT-AD-AdminCenter'
Ensure = 'Present'
}
WindowsFeature RSAT-ADDS-Tools
{
Name = 'RSAT-ADDS-Tools'
Ensure = 'Present'
}
WindowsFeature RSAT-DNS-Server
{
Name = 'RSAT-DNS-Server'
Ensure = 'Present'
}
WindowsFeature RSAT-RDS-Tools
{
Ensure = "Present"
Name = "RSAT-RDS-Tools"
}
WindowsFeature RDS-RD-Server
{
Ensure = "Present"
Name = "RDS-RD-Server"
}
WindowsFeature RDS-Licensing
{
Ensure = "Present"
Name = "RDS-Licensing"
}
WindowsFeature ADDSInstall
{
Ensure = "Present"
Name = "AD-Domain-Services"
}
xADDomain FirstDC
{
DomainName = $DomainName
DomainAdministratorCredential = $DomainCreds
SafemodeAdministratorPassword = $DomainCreds
DatabasePath = "C:\NTDS"
LogPath = "C:\NTDS"
SysvolPath = "C:\SYSVOL"
DependsOn = "[WindowsFeature]ADDSInstall","[xDnsServerAddress]DnsServerAddress"
}
xWaitForADDomain DscForestWait
{
DomainName = $DomainName
DomainUserCredential = $DomainCreds
RetryCount = $RetryCount
RetryIntervalSec = $RetryIntervalSec
DependsOn = "[xADDomain]FirstDC"
}
xADUser FirstUser
{
DomainName = $DomainName
DomainAdministratorCredential = $DomainCreds
UserName = $UserCreds.UserName
Password = $UserCreds
Ensure = "Present"
DependsOn = "[xWaitForADDomain]DscForestWait"
}
xPendingReboot Reboot1
{
Name = "RebootServer"
DependsOn = "[xWaitForADDomain]DscForestWait"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment