Skip to content

Instantly share code, notes, and snippets.

@ludwigschuster
Last active December 7, 2017 12:38
Show Gist options
  • Save ludwigschuster/d5451687e720a92d76eb8345ef3fbba3 to your computer and use it in GitHub Desktop.
Save ludwigschuster/d5451687e720a92d76eb8345ef3fbba3 to your computer and use it in GitHub Desktop.
DSC

Password Abcd.1234 Add-windowsfeature dsc-service Runterladen: https://gallery.technet.microsoft.com/scriptcenter/xComputerManagement-Module-3ad911cc und nach ProgramFiles\WindowsPowerShell\Modules entpacken. Mit Get-DscResources überprüfen. https://gallery.technet.microsoft.com/scriptcenter/xNetworking-Module-818b3583 https://gallery.technet.microsoft.com/scriptcenter/xActiveDirectory-f2d573f3 https://gallery.technet.microsoft.com/scriptcenter/xDhcpServer-PowerShell-f739cf90 Datei testdsc.ps1 erstellen mit

  <#
	    .EXAMPLE
	        . .\testdsc.ps1
	        TestLab -MachineName DSCDC01 -DomainName DSC.lab -Password $localuser -UserName 'LocalAdmin' -SafeModePW $SafeModePW -firstDomainAdmin (Get-Credential -UserName 'LocalAdmin' -Message 'PW für Domai-Admin') -ConfigurationData $configData
	        Start-DscConfiguration -ComputerName localhost -Wait -Force -Verbose -path .\TestLab
	 
	#>
	$secpasswd = ConvertTo-SecureString 'Abcd.1234' -AsPlainText -Force
	$SafeModePW = New-Object System.Management.Automation.PSCredential ('guest', $secpasswd)
	$secpasswd = ConvertTo-SecureString 'Abcd.1234' -AsPlainText -Force
	$localuser = New-Object System.Management.Automation.PSCredential ('guest', $secpasswd)
	configuration TestLab{
	    param(
	        [string[]]$NodeName ='localhost',
	        [Parameter(Mandatory)][string]$MachineName, 
	        [Parameter(Mandatory)][string]$DomainName,
	        [Parameter()]$firstDomainAdmin,
	        [Parameter()][string]$UserName,
	        [Parameter()]$SafeModePW,
	        [Parameter()]$Password
	    ) 
	    Import-DscResource -Module xComputerManagement
	    Import-DscResource -Module xActiveDirectory  
	    Node $NodeName{
	        xComputer NewNameAndWorkgroup{
	            Name          = $MachineName
	            WorkGroupName = 'DSC-Lab'
	        }
	        User LocalAdmin { #Get-DscResource User | select -ExpandProperty Properties | select -expand name
	            UserName = $UserName
	            Description = 'DSC local admin'
	            Ensure = 'Present'
	            FullName = 'Ludwig Schuster'
	            Password = $Password
	            PasswordChangeRequired = $false
	            PasswordNeverExpires = $true
	            DependsOn = '[xComputer]NewNameAndWorkGroup'
	        }
	        Group AddToAdmin{ #Get-DscResource Group | select -expand Properties | Select -expand Name
	            GroupName = 'LocalDSCAdministrators'
	            DependsOn = '[User]LocalAdmin'
	            Ensure = 'Present'
	            MembersToInclude = $UserName
	        }
	        WindowsFeature ADDSInstall { 
	            DependsOn= '[Group]AddToAdmin'
	            Ensure = 'Present'
	            Name = 'AD-Domain-Services'
	            IncludeAllSubFeature = $true
	        }
	        WindowsFeature RSATTools { 
	            DependsOn= '[WindowsFeature]ADDSInstall'
	            Ensure = 'Present'
	            Name = 'RSAT-AD-Tools'
	            IncludeAllSubFeature = $true
	        }  
	        xADDomain SetupDomain {
	            DomainAdministratorCredential= $firstDomainAdmin
	            DomainName= $DomainName
	            SafemodeAdministratorPassword= $SafeModePW
	            DependsOn='[WindowsFeature]RSATTools'
	            DomainNetbiosName = $DomainName.Split('.')[0]
	        }
	 
	    }
	}
	$configData = 'a'
	$configData = @{AllNodes = @(@{NodeName = 'localhost'; PSDscAllowPlainTextPassword = $true})} 

. .\testdsc.ps1 TestLab -MachnineName DSCDC01 -WorkGroupName DSC-Lab -Verbose Start-DscConfiguration -ComputerName localhost -Path .\TestLab -Wait -Force -Verbose Restart-Computer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment