- ####
- # Configure-DC1-2
- # Configures DC1 after dcpromo is completed
- #
- # Version Date What Changed
- # ------- ----------- -------------------------------------------
- # 1.0.0 14 Jan 2013 Initial release
- # 1.1.0 24 Jan 2013 Added code to count how long it all took,
- # Added checkpoint at the end of this script
- # 1.1.1 25 Jan 2013 Added auto admin logon
- # 1.1.2 5 Feb 2013 Added forced reboot of DC1-1 at script end
- ####
- # Configuration block
- $Conf = {
- $StartTime = Get-Date
- Write-Host "Starting at: $StartTime"
- # Set Credentials for use in this configuration block
- $User = "Reskit\Administrator"
- $Password = 'Pa$$w0rd'
- $PasswordSS = ConvertTo-SecureString -String $Password –AsPlainText `
- -Force
- $Dom = 'Reskit'
- $CredRK = New-Object `
- -Typename System.Management.Automation.PSCredential `
- -Argumentlist $User,$PasswordSS
- # Define registry path for autologon, then set admin logon
- $RegPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
- Set-ItemProperty -Path $RegPath -Name AutoAdminLogon `
- -Value 1 -EA 0
- Set-ItemProperty -Path $RegPath -Name DefaultUserName `
- -Value $User -EA 0
- Set-ItemProperty -Path $RegPath -Name DefaultPassword `
- -Value $Password -EA 0
- Set-ItemProperty -Path $RegPath -Name DefaultDomainName `
- -Value $Dom -EA 0
- # Install key Windows features for labs
- Write-Verbose 'Installing Windows fetures needed for DC1'
- $Features = @('PowerShell-ISE',
- 'Hyper-V-PowerShell',
- 'Rsat-AD-PowerShell',
- 'Web-Server','Web-Mgmt-Tools',
- 'Web-Mgmt-Console',
- 'Web-Scripting-Tools',
- 'Telnet-Client')
- Install-WindowsFeature @Features -IncludeManagementTools -Verbose
- # Install and configure DHCP
- Write-Verbose -Message 'Adding and then configuring DHCP'
- Install-WindowsFeature DHCP -IncludeManagementTools
- Add-DhcpServerV4Scope -Name "ReskitNet0" `
- -StartRange 10.0.0.100 `
- -EndRange 10.0.0.119 `
- -SubnetMask 255.255.255.0
- Set-DhcpServerV4OptionValue -DnsDomain Reskit.Org `
- -DnsServer 10.0.0.10
- Add-DhcpServerInDC -DnsName Dc1.reskit.org
- # Add users to the AD and then add them to some groups
- # Hash table for common new user paraemters
- Write-Verbose -Message
- $NewUserHT = @{AccountPassword = $PasswordSS;
- Enabled = $true;
- PasswordNeverExpires = $true;
- ChangePasswordAtLogon = $false
- }
- # Create one new user (me!) and add to enterprise and domain admins security groups
- New-ADUser @NewUserHT -SamAccountName tfl `
- -UserPrincipalName 'tfl@reskit.org' `
- -Name "tfl" `
- -DisplayName 'Thomas Lee'
- Add-ADPrincipalGroupMembership `
- -Identity "CN=tfl,CN=Users,DC=reskit,DC=org" `
- -MemberOf "CN=Enterprise Admins,CN=Users,DC=reskit,DC=org" ,
- "CN=Domain Admins,CN=Users,DC=reskit,DC=org"
- # Say nice things and finish
- $FinishTime = Get-Date
- Write-Verbose "Finished at: $FinishTime"
- Write-Verbose "DC1 Configuration took $(($FinishTime - $StartTime).TotalSeconds.ToString('n2')) seconds"
- } # End Conf configuration script block
- # Start of script proper
- # Set Credentials
- $Username = "Reskit\administrator"
- $Password = 'Pa$$w0rd'
- $PasswordSS = ConvertTo-SecureString -String $Password -AsPlainText
- -Force
- $CredRK = New-Object -Typename System.Management.Automation.PSCredential `
- -Argumentlist $Username,$PasswordSS
- # Following code used to test the credentials. Remove the comments on next two lines the first time you
- # run this script
- Invoke-Command -ComputerName DC1 -ScriptBlock {hostname} -Credential $Credrk -verbose
- Pause
- Invoke-Command -ComputerName DC1 -Scriptblock $conf -Credential $CredRK `
- -Verbose
- # OK - script block has completed - reboot the system and wait till it comes up
- Restart-Computer -ComputerName DC1 -Wait -For PowerShell –Force
- -Credential $CredRK
- # Finally, run a post-DCPromo snapshot
- Checkpoint-VM -VM $(Get-VM DC1) `
- -SnapshotName "DC1 - post configuration by ConfigureDC1-2.ps1"
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 4 February 2013
Configure-DC1-2.ps1
Subscribe to:
Post Comments (Atom)
1 comment:
Nice post. Got a lot of important stuff from this blog.
dba kings
Post a Comment