Skip to content

Instantly share code, notes, and snippets.

@vhusker
Created March 10, 2015 11:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhusker/c6560348976e56cd4daa to your computer and use it in GitHub Desktop.
Save vhusker/c6560348976e56cd4daa to your computer and use it in GitHub Desktop.
Build App Server for a DSC Demo
$ConfigData =@{
AllNodes = @(
@{
NodeName = "localhost"
PSDSCAllowPlainTextPassword = $True
}
)
}
Configuration BuildLabAppServer{
param(
[parameter(Mandatory)]
[ValidateNotNullorEmpty()]
[string]$NodeName,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$ComputerName,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$Domain,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$IP,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$DNSIP,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$Gateway,
[parameter(Mandatory=$True)]
[ValidateNotNullorEmpty()]
[string]$Subnet
)
#unsecure, not safe or recommended way to do this
$Creds = ConvertTo-SecureString "Passw0rd!" -AsPlainText -Force
$DomainAdminCred = New-Object System.Management.Automation.PSCredential ("$Domain\Administrator", $Creds)
$SafeModeAdminCred = New-Object System.Management.Automation.PSCredential ("Administrator", $Creds)
Import-DscResource -ModuleName xNetworking,xComputerManagement,xPendingReboot,xActiveDirectory
Node $NodeName{
LocalConfigurationManager{
RebootNodeIfNeeded = $True
}
xIPAddress APPIP{
IPAddress = $IP
DefaultGateway = $Gateway
SubnetMask = $Subnet
AddressFamily = "IPv4"
InterfaceAlias = "Ethernet"
}
xDNSServerAddress DomainDNS{
Address = $DNSIP
InterfaceAlias = "Ethernet"
AddressFamily = "IPv4"
}
xComputer RenameAndDomainJoin{
Name = $ComputerName
DomainName = $Domain
Credential = $DomainAdminCred
DependsOn = "[xIPAddress]APPIP","[xDNSServerAddress]DomainDNS"
}
xPendingReboot DomainJoin{
Name = "Check for reboot after domain join"
}
}#Node
}#configuration
BuildLabAppServer -ConfigurationData $ConfigData -NodeName localhost -computername $YourComputerName -Domain $YourDomain -IP $YourIP -Gateway $YourGateway -Subnet 24 -DNSIP $YourDNS -OutputPath $YourPath
Set-DscLocalConfigurationManager -Path $YourPath
Get-DSCLocalConfigurationManager
Start-DscConfiguration -Wait -Force -Verbose -Path $YourPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment