Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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