Last active
October 16, 2016 01:54
-
-
Save brianfgonzalez/d853f126fa3421f3c796aa5554b7233f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param([string]$Phase = "A") | |
#$VerbosePreference = "Continue" | |
# Give system time to start up and re-connect to vagrant shares. | |
#Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\NetTCPIP\NetTCPIP.psd1" | |
#Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ServerManager\ServerManager.psd1" | |
$scriptPath = $myInvocation.MyCommand.Definition | |
function DCRoleInstall { | |
$SafeModeAdministratorPasswordText = "P@ssw0rd" | |
$SafeModeAdministratorPassword = ConvertTo-SecureString -AsPlainText $SafeModeAdministratorPasswordText -Force | |
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools | |
Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\ADDSDeployment\ADDSDeployment.psd1" | |
Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath "$env:SystemDrive\Windows\NTDS" -DomainMode "Win2012R2" -DomainName "pdeploy.com" ` | |
-DomainNetbiosName "pdeploy" -ForestMode "Win2012R2" -InstallDns:$true -LogPath "$env:SystemDrive\Windows\NTDS" -NoRebootOnCompletion:$true ` | |
-SysvolPath "$env:SystemDrive\Windows\SYSVOL" -Force:$true -SafeModeAdministratorPassword $SafeModeAdministratorPassword | |
} | |
function DHCPWDSRoleInstall { | |
Add-ADGroupMember "Domain Admins" "vagrant" | |
Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools | |
Install-WindowsFeature WDS -IncludeManagementTools | |
} | |
function AddtRoleConfig { | |
Start-Process -FilePath "cmd.exe" -ArgumentList "/c wdsutil /initialize-server /reminst:`"$env:SystemDrive\RemoteInstall`"" -Wait -NoNewWindow | |
Start-Process -FilePath "cmd.exe" -ArgumentList "/c wdsutil /set-server /answerclients:all" -Wait -NoNewWindow | |
Import-Module "$env:WinDir\system32\WindowsPowerShell\v1.0\Modules\DhcpServer\DhcpServer.psd1" | |
Add-DhcpServerv4Scope -Name "Bridged" -StartRange "192.168.50.100" -EndRange "192.168.50.250" -SubnetMask "255.255.255.0" -Description "Internal Network" | |
Add-DhcpServerInDC | |
Restart-Service -DisplayName "Windows Deployment Services Server" | |
#Import-WdsBootImage -Path "$env:SystemDrive\DeploymentShare\Boot\LitetouchPE_x64.wim" | |
} | |
function CallRestart{ | |
Param ([string]$nextPhase) | |
'powershell.exe -File "'+$scriptPath+'" "'+$nextPhase+'" >> "'+$env:SystemDrive+'\tmp\debug.log" 2>&1' | ` | |
Out-File "$env:SystemDrive\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Continue Provisioning.bat" -Force -Encoding "default" | |
Restart-Computer -Force | |
Exit | |
} | |
function ClearRestart{ | |
if (Test-Path -Path "$env:SystemDrive\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Continue Provisioning.bat") { | |
Remove-Item -Path "$env:SystemDrive\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\Continue Provisioning.bat" -Force | |
} | |
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "AutoAdminLogon" -Value "0" | |
} | |
if ($Phase -eq "A") { | |
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False | |
DCRoleInstall | |
CallRestart -nextPhase "B" | |
} | |
if ($Phase -eq "B") { | |
DHCPWDSRoleInstall | |
CallRestart -nextPhase "C" | |
} | |
if ($Phase -eq "C") { | |
AddtRoleConfig | |
} | |
ClearRestart | |
Copy-Item -Path "\tmp\debug.log" -Destination "$env:USERPROFILE\Desktop\complete.log" -Force | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
[System.Windows.Forms.MessageBox]::Show("Configuration is complete and ready for use..logpath: $env:USERPROFILE\Desktop\complete.log" , "Status") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment