########## BEGIN SCRIPT HEADER ########## # WINDOWS AUTOMATED SERVER SETUP SCRIPT # Author: Anthony Marino # Version: V1.0.3 # Date: 10/3/2015 ########## END SCRIPT HEADER ########## ##### REQUIREMENTS ##### # Powershell execution policy must be set to unrestricted, bypass or remote signed. # You must specify the location of variables.xml, using the -VariableFiles parameter. Param( [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$VariablesFile ) # Create a registry key to track progress IF (!(Test-Path "HKLM:\SOFTWARE\Datapipe\AutomatedServerSetup" -ErrorAction SilentlyContinue)) { REG ADD "HKLM\SOFTWARE\Datapipe\AutomatedServerSetup" } REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d InProgress /f | Out-Null # If the log file does not exist, create it. IF (!(Test-Path "C:\Windows\Temp\DPAutomation.log")) { New-Item -ItemType File "C:\Windows\Temp\DPAutomation.log" } # Import variables $CurrentErrorCount = $Error.Count $xml = [XML](Get-Content $VariablesFile) $ErrorCount = $Error.Count IF ($ErrorCount -gt $CurrentErrorCount) { # Failed to import variables.xml "UNABLE TO IMPORT Variables.xml, FROM THE SPECIFIED LOCATION: $VariablesFile" | Add-Content "C:\Windows\Temp\DPAutomation.log" ($error | select -Last 1) | Add-Content "C:\Windows\Temp\DPAutomation.log" REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d Failed /f | Out-Null exit (1) } ELSE { "IMPORTED Variables.xml, FROM THE SPECIFIED LOCATION: $VariablesFile" | Add-Content "C:\Windows\Temp\DPAutomation.log" } # Transcode variables $PSM = $XML.Variables.AutomationSettings.WindowsPSMPath $Download1 = $xml.Variables.FileDownloads.Download1 $Download2 = $xml.Variables.FileDownloads.Download2 $Download3 = $xml.Variables.FileDownloads.Download3 $Download4 = $xml.Variables.FileDownloads.Download4 $Download5 = $xml.Variables.FileDownloads.Download5 $Download6 = $xml.Variables.FileDownloads.Download6 $Download7 = $xml.Variables.FileDownloads.Download7 $Download8 = $xml.Variables.FileDownloads.Download8 $Download9 = $xml.Variables.FileDownloads.Download9 $Download10 = $xml.Variables.FileDownloads.Download10 $AdditionalPSM1 = $XML.Variables.Modules.AdditionalPSM1 $AdditionalPSM2 = $XML.Variables.Modules.AdditionalPSM2 $AdditionalPSM3 = $XML.Variables.Modules.AdditionalPSM3 $AdditionalPSM4 = $XML.Variables.Modules.AdditionalPSM4 # Import the Windows PSM Import-Module $PSM -Force IF (!(DPWindowsPSMCommands)) { # Failed to the Windows PSM "UNABLE TO IMPORT THE WINDOWS PSM, FROM THE SPECIFIED LOCATION: $PSM" | Add-Content "C:\Windows\Temp\DPAutomation.log" ($error | select -Last 1) | Add-Content "C:\Windows\Temp\DPAutomation.log" REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d Failed /f | Out-Null exit (1) } ELSE { DPLOG -Type INFO -Message "IMPORTED THE WINDOWS PSM, FROM THE SPECIFIED LOCATION: $PSM" | Add-Content "C:\Windows\Temp\DPAutomation.log" } # If unattended setup is not enabled, format Powershell and prompt the user to continue IF ($XML.Variables.AutomationSettings.UnattendedSetup -eq $true) { DPLog -Type INFO -Message "UNATTENDED SETUP MODE DETECTED." } ElSE { DPLog -Type INFO -Message "UNATTENDED SETUP MODE NOT DETECTED." # Set environment $Host.UI.RawUI.BackgroundColor = "Black"; Clear-Host $Host.UI.RawUI.WindowTitle = "Server Setup Utility - $ScriptVer - $ScriptDate" # Prompt user to continue $a = new-object -comobject wscript.shell $intAnswer = $a.popup("Are you sure you want to continue? The utility will configure this server, requiring a reboot upon completion? Press Yes to continue or No to exit.", ` 0,"Continue?",4) If (!($intAnswer -eq 6)) { # User choose to exit REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d Cancelled /f | Out-Null exit } } # PS transcript IF (($xml.Variables.AutomationSettings.EnablePSTranscript) -eq $true) { $Date = (get-date -Format MMddyyyy_HHMMSS) $Filename = "C:\Windows\Temp\PSTranscript-$Date.txt" DPLog -Type INFO -Message "OPTION TO ENABLE POWERSHELL TRANSCRIPT DETECTED. TRANSCRIPT WILL BE SAVED TO: $Filename." Start-Transcript $Filename } ELSE { DPLog -Type INFO -Message "OPTION TO ENABLE POWERSHELL TRANSCRIPT NOT DETECTED." } $Hostname = $xml.Variables.General.ServerName # Send start email IF (($xml.Variables.Email.EmailTo) -ne "") { DPLog -Type INFO -Message "OPTION TO SEND EMAIL DETECTED." DPSendEmail -To ($xml.Variables.Email.EmailTo) -Subject "Automated Server Setup Started - Hostname: $Hostname" -Body "The automated server setup on hostname: $Hostname has started." } ELSE { DPLog -Type INFO -Message "OPTION TO SEND EMAIL NOT DETECTED." } # Download files Function Download( [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$False)] [string]$DownloadSource, [Parameter(Position=2, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$False)] [string]$DownloadDestination ) { DPLog -Type INFO -Message "OPTION TO DOWNLOAD A FILE DETECTED. DOWNLOADING: $DownloadDestination." DPDownloadFile -Source $DownloadSource -Destination $DownloadDestination Write-Host $DownloadSource } $DownloadSource = $xml.Variables.FileDownloads.Download1.Source $DownloadDestination = $xml.Variables.FileDownloads.Download1.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download2.Source $DownloadDestination = $xml.Variables.FileDownloads.Download2.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download3.Source $DownloadDestination = $xml.Variables.FileDownloads.Download3.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download4.Source $DownloadDestination = $xml.Variables.FileDownloads.Download4.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download5.Source $DownloadDestination = $xml.Variables.FileDownloads.Download5.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download6.Source $DownloadDestination = $xml.Variables.FileDownloads.Download6.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download7.Source $DownloadDestination = $xml.Variables.FileDownloads.Download7.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download8.Source $DownloadDestination = $xml.Variables.FileDownloads.Download8.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download9.Source $DownloadDestination = $xml.Variables.FileDownloads.Download9.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } $DownloadSource = $xml.Variables.FileDownloads.Download10.Source $DownloadDestination = $xml.Variables.FileDownloads.Download10.Destination IF (($DownloadSource -gt "0") -and ($DownloadDestination -gt "0")) { Download -DownloadSource $DownloadSource -DownloadDestination $DownloadDestination } # Run pre-configuration PS1 scripts Function RunPreconfig( [Parameter(Position=1, Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$PreConfig ) { IF ($PreConfig.EndsWith(".ps1")) { DPLog -Type INFO -Message "OPTION TO RUN A PRE-CONFIGURATION PS1 SCRIPT DETECTED. RUNNING: $PreConfig." Invoke-Expression $PreConfig } IF (($PreConfig.EndsWith(".bat")) -or ($PreConfig.EndsWith(".cmd"))) { DPLog -Type INFO -Message "OPTION TO RUN A PRE-CONFIGURATION BATCH SCRIPT DETECTED. RUNNING: $PreConfig." cmd.exe /c $PreConfig } IF ($PreConfig.EndsWith(".exe")) { DPLog -Type INFO -Message "OPTION TO RUN A PRE-CONFIGURATION EXECUTABLE DETECTED. RUNNING: $PreConfig." Start-Process $PreConfig -Wait } } RunPreconfig ($xml.Variables.PreConfiguration.PSScript1) RunPreconfig ($xml.Variables.PreConfiguration.PSScript2) RunPreconfig ($xml.Variables.PreConfiguration.PSScript3) RunPreconfig ($xml.Variables.PreConfiguration.PSScript4) RunPreconfig ($xml.Variables.PreConfiguration.Batch1) RunPreconfig ($xml.Variables.PreConfiguration.Batch2) RunPreconfig ($xml.Variables.PreConfiguration.Batch3) RunPreconfig ($xml.Variables.PreConfiguration.Batch4) RunPreconfig ($xml.Variables.PreConfiguration.EXE1) RunPreconfig ($xml.Variables.PreConfiguration.EXE2) RunPreconfig ($xml.Variables.PreConfiguration.EXE3) RunPreconfig ($xml.Variables.PreConfiguration.EXE4) # Import additional modules ##### Function PSMImport( [Parameter(Position=1, Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$AdditonalPSM ) { IF ($AdditonalPSM -gt "0") { IF (Test-Path $AdditonalPSM) { Import-Module $AdditonalPSM -Force DPLog -Type INFO -Message "ADDITIONAL PSM: $AdditonalPSM SPECIFIED, LOCATED AND IMPORTED." } ELSE { DPLog -Type INFO -Message "ADDITIONAL PSM: $AdditonalPSM WAS SPECIFIED BUT COULD NOT BE LOCATED. EXITING." REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d Failed /f | Out-Null exit (1) } } } PSMImport $AdditionalPSM1 PSMImport $AdditionalPSM2 PSMImport $AdditionalPSM3 PSMImport $AdditionalPSM4 # Import server module Import-Module ServerManager # Check if preset was used IF (($xml.Variables.General.Preset) -ne "") { $Preset = ($xml.Variables.General.Preset) DPLog -Type INFO -Message "PRESET DETECTED: $Preset" } ELSE { DPLog -Type INFO -MEssage "PRESET NOT DETECTED" } # Licensing IF (($xml.Variables.WindowsLicensing.Key) -gt "0") { IF (($xml.Variables.WindowsLicensing.Force) -eq $true) { DPLog -Type INFO -Message "OPTION TO LICENSE WINDOWS USING THE FORCE OPTION DETECTED." DPLicenseWindows -Key ($xml.Variables.WindowsLicensing.Key) -Force } ELSE { DPLog -Type INFO -Message "OPTION TO LICENSE WINDOWS WITHOUT THE FORCE OPTION DETECTED." DPLicenseWindows -Key ($xml.Variables.WindowsLicensing.Key) } } ELSE { DPLog -Type INFO -Message "OPTION TO LICENSE WINDOWS NOT DETECTED. SKIPPING." } # DNS $DNS = $xml.Variables.Network.DNS IF ((($DNS.BaseIP) -gt "0") -and (($DNS.DNS1) -gt "0")) { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS2) -gt "0") -and (($DNS.DNS3) -gt "0") -and (($DNS.DNS4) -gt "0") -and (($DNS.DNS5) -gt "0") -and (($DNS.DNS6) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 6 DNS SERVERS DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 -DNS2 $DNS.DNS2 -DNS3 $DNS.DNS3 -DNS4 $DNS.DNS4 -DNS5 $DNS.DNS5 -DNS6 $DNS.DNS6 } ELSE { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS2) -gt "0") -and (($DNS.DNS3) -gt "0") -and (($DNS.DNS4) -gt "0") -and (($DNS.DNS5) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 5 DNS SERVERS DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 -DNS2 $DNS.DNS2 -DNS3 $DNS.DNS3 -DNS4 $DNS.DNS4 -DNS5 $DNS.DNS5 } ELSE { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS2) -gt "0") -and (($DNS.DNS3) -gt "0") -and (($DNS.DNS4) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 4 DNS SERVERS DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 -DNS2 $DNS.DNS2 -DNS3 $DNS.DNS3 -DNS4 $DNS.DNS4 } ELSE { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS2) -gt "0") -and (($DNS.DNS3) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 3 DNS SERVERS DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 -DNS2 $DNS.DNS2 -DNS3 $DNS.DNS3 } ELSE { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS2) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 2 DNS SERVERS DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 -DNS2 $DNS.DNS2 } ELSE { IF ((($DNS.DNS1) -gt "0") -and (($DNS.DNS1) -gt "0")) { DPLog -Type INFO -Message "OPTION TO CONFIGURE 1 DNS SERVER DETECTED." DPSetDNSServers -BaseIP $DNS.BaseIP -DNS1 $DNS.DNS1 } } } } } } } ELSE { DPLog -Type INFO -Message "OPTION TO CONFIGURE DNS SERVERS NOT DETECTED. SKIPPING." } # Timezone IF (($xml.Variables.General.Timezone) -ne "") { # Timezone detected. Create variable for the timezone and trim the whitespace. $Timezone = $xml.Variables.General.Timezone.TrimEnd() DPSetTimezone $Timezone } ELSE { DPLog -Type INFO -Message "OPTION TO CHANGE THE TIMEZONE NOT DETECTED. SKIPPING." } # NTP IF (($xml.Variables.General.NTPServer) -gt "0") { # Turn xml into a variable $NTPServer = ($xml.Variables.General.NTPServer) IF (($xml.Variables.General.NTPServer) -eq "San Jose") {$NTPServer = "SJC"} IF (($xml.Variables.General.NTPServer) -eq "Somerset") {$NTPServer = "EWR"} IF (($xml.Variables.General.NTPServer) -eq "London") {$NTPServer = "LON"} IF (($xml.Variables.General.NTPServer) -eq "Hong Kong") {$NTPServer = "HKG"} IF ($NTPServer -gt "0") { DPLog -Type INFO -Message "NTP SERVER AND MODE DETECTED." $NTPMode = ($xml.Variables.General.NTPMode) DPSetNTP -Server $NTPServer -Mode $NTPMode } ELSE { DPLog -Type INFO -Message "NTP SERVER DETECTED." DPSetNTP -Server $NTPServer } } ELSE { DPLog -Type INFO -Message "NTP SERVER NOT DETECTED. SKIPPING." } # Page file $Drive1 = ($xml.Variables.PageFile.PageFileDrive1Letter) $Drive1Size = ($xml.Variables.PageFile.PageFileDrive1Size) $Drive2 = ($xml.Variables.PageFile.PageFileDrive1Letter) $Drive2Size = ($xml.Variables.PageFile.PageFileDrive1Size) # Strip GB from drive size $Drive1Size = $Drive1Size.TrimEnd("GB") $Drive2Size = $Drive2Size.TrimEnd("GB") # Make sure the drive letter ends in : IF (!($Drive1.EndsWith(":"))) { $Drive1 = $Drive1+":" } IF (!($Drive2.EndsWith(":"))) { $Drive2 = $Drive2+":" } IF ($Drive1 -gt "0") { DPLog -Type INFO -Message "OPTION TO CHANGE THE PAGE FILE DETECTED." IF ($Drive1Size -gt "0") { IF (($Drive2 -gt "0") -and ($Drive2Size -gt "0")) { DPSetPageFile -Drive1 $Drive1 -Drive1Size $Drive1Size -Drive2 $Drive2 -Drive2Size $Drive2Size } ELSE { DPSetPageFile -Drive1 $Drive1 -Drive1Size $Drive1Size -Drive2 $Drive2 -Drive2Size $Drive2Size } } ELSE { DPLog -Type INFO -Message "DRIVE AND PAGE FILE SIZE OPTIONS NOT DETECTED. USING AUTOMATIC MODE." DPSetPageFile } } ELSE { DPLog -Type INFO -Message "OPTION TO CHANGE THE PAGE FILE NOT DETECTED. SKIPPING." } # Windows Firewall IF (($xml.Variables.WindowsFW.PrivateDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL PRIVATE PROFILE DETECTED." DPDisableWindowsFW -PrivateProfile } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL PRIVATE PROFILE NOT DETECTED. SKIPPING." } IF (($xml.Variables.WindowsFW.PublicDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL PUBLIC PROFILE DETECTED." DPDisableWindowsFW -PublicProfile } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL PUBLIC PROFILE NOT DETECTED. SKIPPING." } IF (($xml.Variables.WindowsFW.DomainDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL DOMAIN PROFILE DETECTED." DPDisableWindowsFW -DomainProfile } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS FIREWALL DOMAIN PROFILE NOT DETECTED. SKIPPING." } # Unnecessary services IF (($xml.Variables.Services.SmartCardDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE SMART CARD SERVICE DETECTED." DPDisableUnnecessaryServices -SmartCard } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE SMART CARD SERVICE NOT DETECTED. SKIPPING." } IF (($xml.Variables.Services.SmartCardRemovalDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE SMART CARD REMOVAL POLICY SERVICE DETECTED." DPDisableUnnecessaryServices -SmartCardRemovalPolicy } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE SMART CARD REMOVAL POLICY SERVICENOT DETECTED. SKIPPING." } IF (($xml.Variables.Services.AudioDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS AUDIO SERVICE DETECTED." DPDisableUnnecessaryServices -WindowsAudio } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS AUDIO NOT DETECTED. SKIPPING." } # Disable offload IF (($xml.Variables.Offload.TCPDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE TCP CHIMNEY OFFLOAD DETECTED." DPDisableOffload -TCP } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE TCP CHIMNEY OFFLOAD NOT DETECTED. SKIPPING." } IF (($xml.Variables.Offload.RSSDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE RECEIVE SIDE SCALING DETECTED." DPDisableOffload -RSS } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE RECEIVE SIDE SCALING NOT DETECTED. SKIPPING." } # Hibernation IF (($xml.Variables.Power.HibernationDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE HIBERNATION DETECTED." DPDisableHibernation } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE HIBERNATION NOT DETECTED. SKIPPING." } # High performance mode IF (($xml.Variables.Power.HighPerformanceEnable) -eq $true) { DPLog -Type INFO -Message "OPTION TO ENABLE HIGH PERFORMANCE MODE DETECTED." DPSetHighPerformanceMode } ELSE { DPLog -Type INFO -Message "OPTION TO ENABLE HIGH PERFORMANCE MODE NOT DETECTED. SKIPPING." } # UAC IF (($xml.Variables.Misc.UACDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE UAC DETECTED." DPDisableUAC } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE UAC NOT DETECTED. SKIPPING." } # IPV6 IF (($xml.Variables.Misc.IPV6Disable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE IPV6 DETECTED." DPDisableIPV6 } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE IPV6 NOT DETECTED. SKIPPING." } # IE ESC IF (($xml.Variables.Misc.IEESCDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE IE ESC DETECTED." DPDisableUAC } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE IE ESC NOT DETECTED. SKIPPING." } # Volume Notification IF (($xml.Variables.Misc.VolumeDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS VOLUME NOTIFICATION DETECTED." DPDisableVolumeNotification } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE WINDOWS VOLUME NOTIFICATION DETECTED. SKIPPING." } # Automatic disk optimization IF (($xml.Variables.Misc.DiskOpimizationDisable) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE AUTOMATIC DISK OPTIMIZATION DETECTED." DPDisableDiskOptimization } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE AUTOMATIC DISK OPTIMIZATION DETECTED. SKIPPING." } # Event log size IF (($xml.Variables.EventLog.MaxSize.Application) -eq $true) { DPLog -Type INFO -Message "OPTION TO ADJUST APPLICATION EVENT LOG SIZE DETECTED." DPSetLogSize -Log Application -MaxSizeMB 1024 } ELSE { DPLog -Type INFO -Message "OPTION TO ADJUST APPLICATION EVENT LOG SIZE DETECTED. SKIPPING." } IF (($xml.Variables.EventLog.MaxSize.System) -eq $true) { DPLog -Type INFO -Message "OPTION TO ADJUST SYSTEM EVENT LOG SIZE DETECTED." DPSetLogSize -Log System -MaxSizeMB 1024 } ELSE { DPLog -Type INFO -Message "OPTION TO ADJUST SYSTEM EVENT LOG SIZE DETECTED. SKIPPING." } IF (($xml.Variables.EventLog.MaxSize.Security) -eq $true) { DPLog -Type INFO -Message "OPTION TO ADJUST SECURITY EVENT LOG SIZE DETECTED." DPSetLogSize -Log Security -MaxSizeMB 1024 } ELSE { DPLog -Type INFO -Message "OPTION TO ADJUST SECURITY EVENT LOG SIZE DETECTED. SKIPPING." } # RDP timeouts IF (($xml.Variables.RDP.DisableIdleTimeout) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE RDP IDLE SESSION TIMEOUT DETECTED." DPDisableRDPTimeouts -IdleSession } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE RDP IDLE SESSION TIMEOUT NOT DETECTED. SKIPPING." } IF (($xml.Variables.RDP.DisconnectTimeout) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE RDP DISCONNECTED SESSION TIMEOUT DETECTED." DPDisableRDPTimeouts -DisconnectedSession } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE RDP DISCONNECTED SESSION TIMEOUT NOT DETECTED. SKIPPING." } # Install IIS IF (($xml.Variables.Apps.IISInstall) -eq $true) { DPLog -Type INFO -Message "OPTION TO INSTALL IIS DETECTED." IF (($xml.Variables.Apps.IISLogLocation) -lt "0") { DPLog -Type INFO -Message "OPTION TO CONFIGURE CUSTOM LOG FILE LOCATION DETECTED." DPInstallIIS -LogLocation ($xml.Variables.Apps.IISLogLocation) } ELSE { DPLog -Type INFO -Message "OPTION TO CONFIGURE CUSTOM LOG FILE LOCATION NOT DETECTED." DPInstallIIS } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL IIS NOT DETECTED." } # MPIO IF (($xml.Variables.Apps.MPIOInstall) -eq $true) { IF (($xml.Variables.Apps.MPIOIdentifier) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO WITH AN IDENTIFIER DETECTED." IF (($xml.Variables.Apps.MPIOLocalInstallDir) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO HOTIFIXES USING LOCAL INSTALLERS DETECTED." DPInstallMPIO -Identifier ($xml.Variables.Apps.MPIOIdentifier) -LocalInstallDir ($xml.Variables.Apps.MPIOLocalInstallDir) } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO HOTIFIXES USING REMOTE INSTALLERS DETECTED." DPInstallMPIO -Identifier ($xml.Variables.Apps.MPIOIdentifier) } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO WITHOUT AN IDENTIFIER DETECTED." IF (($xml.Variables.Apps.MPIOLocalInstallDir) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO HOTIFIXES USING LOCAL INSTALLERS DETECTED." DPInstallMPIO -LocalInstallDir ($xml.Variables.Apps.MPIOLocalInstallDir) } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO HOTIFIXES USING REMOTE INSTALLERS DETECTED." DPInstallMPIO } } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL MPIO NOT DETECTED DETECTED. SKIPPING." } # Harden SSL IF (($xml.Variables.Misc.HardenSSL) -eq $true) { DPLog -Type INFO -Message "OPTION TO HARDEN SSL DETECTED." DPHardenSSL } ELSE { DPLog -Type INFO -Message "OPTION TO HARDEN SSL NOT DETECTED." } # .NET 3.5 IF (($EM7.Apps.NET35Install) -eq $true) { DPLog -Type INFO -Message "OPTION TO INSTALL .NET 3.5 DETECTED." DPInstallNET35 } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL .NET 3.5 NOT DETECTED. SKIPPING." } # .NET 4.5 IF (($EM7.Apps.NET45Install) -eq $true) { DPLog -Type INFO -Message "OPTION TO INSTALL .NET 4.5.2 DETECTED." DPInstallNET452 } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL .NET 4.5.2 NOT DETECTED. SKIPPING." } # Install Observer IF (($xml.Variables.Observer.Install) -eq $true) { IF (($xml.Variables.Observer.LocalInstallFile) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL OBSERVER USING A LOCAL INSTALLER DETECTED." DPInstallObserver -LocalInstallFile ($xml.Variables.Observer.LocalInstallFile) } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL OBSERVER USING A REMOTE INSTALLER DETECTED." DPInstallObserver } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL OBSERVER NOT DETECTED. SKIPPING." } # SNMP $EM7 = ($xml.Variables.EM7) IF (($EM7.SNMPInstall) -eq $true) { IF (($EM7.SNMPLocalInstallerDir) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL EM7 (SNMP) USING LOCAL INSTALLERS DETECTED." DPInstallEM7 -Collector1 $EM7.SNMPCollector2 -Collector2 $EM7.SNMPCollector2 -Collector3 $EM7.SNMPCollector3 -Collector4 $EM7.SNMPCollector4 -Collector5 $EM7.SNMPCollector5 -Collector6 $EM7.SNMPCollector6 -Collector7 $EM7.SNMPCollector7 -Collector8 $EM7.SNMPCollector8 -CommunityString $EM7.SNMPCommunityString -TrapDestination $EM7.SNMPTrapDesintation -LocalInstallerDir $EM7.LocalInstallerDir } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL EM7 (SNMP) USING REMOTE INSTALLERS DETECTED." DPInstallEM7 -Collector1 $EM7.SNMPCollector2 -Collector2 $EM7.SNMPCollector2 -Collector3 $EM7.SNMPCollector3 -Collector4 $EM7.SNMPCollector4 -Collector5 $EM7.SNMPCollector5 -Collector6 $EM7.SNMPCollector6 -Collector7 $EM7.SNMPCollector7 -Collector8 $EM7.SNMPCollector8 -CommunityString $EM7.SNMPCommunityString -TrapDestination $EM7.SNMPTrapDesintation } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL EM7 (SNMP) NOT DETECTED. SKIPPING." } # SSH agent IF (($EM7.SSHAgentInstall) -eq $true) { IF (($EM7.SSHAgentLocalInstallerDir) -gt "0") { DPLog -Type INFO -Message "OPTION TO INSTALL THE SSH AGENT USING LOCAL INSTALLER DETECTED." DPInstallSSHAgent -LocalInstallerDir $EM7.SSHAgentLocalInstallerDir } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL THE SSH AGENT USING REMOTE DETECTED." DPInstallSSHAgent } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL THE SSH AGENT NOT DETECTED. SKIPPING." } # BES $BES = ($xml.Variables.BES) IF (($BES.Install) -eq $true) { IF (($BES.LICPartner) -gt "0") { $License = "Partner" } ELSE { $License = "SPLA" } # Turn XML into Variables $Team = $BES.Team $Department = $BES.Department $Group = $BES.Group $Subgroup = $BES.Subgroup $BusinessUnit = $BES.BusinessService $Location = $BES.Location IF ($Location -eq "San Jose") { $Location = '"San Jose"' } $Platform = $BES.Platform $Environment = $BES.Environment IF ($Environment -eq "PRD") { $Environment = "PROD" } $AccountID = $BES.AccountID $CustomerID = $BES.CustomerID $DeviceID = $BES.DeviceID $ServerID = $BES.ServerID $InternalLicensing = $License $CPLExchange = $BES.CPLExchange $CPLLync = $BES.CPLLync $CPLOffice = $BES.CPLLync $CPLOS = $BES.CPLOS $CPLProject = $BES.CPLProject $CPLSSharepoint = $BES.CPLSharepoint $CPLSQLServer = $BES.CPLSQL $CPLVisio = $BES.CPLVisio $CPLVS = $BES.CPLVisualStudio $Relay1 = $BES.Relay1 $Relay2 = $BES.Relay2 $LocalInstallDir = $BES.LocalInstallerDir # Create install string $InstallString = "DPInstallBES" IF ($Team -gt "0") { $InstallString = "$InstallString -Team $Team" } IF ($Department -gt "0") { $InstallString = "$InstallString -Department $Department" } IF ($Group -gt "0") { $InstallString = "$InstallString -Group $Group" } IF ($Subgroup -gt "0") { $InstallString = "$InstallString -Subgroup $Subgroup" } IF ($BusinessUnit -gt "0") { $InstallString = "$InstallString -BusinessUnit $BusinessUnit" } IF ($Location.length -gt "1") { $InstallString = "$InstallString -Location $Location" } IF ($Platform -gt "0") { $InstallString = "$InstallString -Platform $Platform" } IF ($Environment -gt "0") { $InstallString = "$InstallString -Environment $Environment" } IF ($AccountID -gt "0") { $InstallString = "$InstallString -AccountID $AccountID" } IF ($CustomerID -gt "0") { $InstallString = "$InstallString -CustomerID $CustomerID" } IF ($DeviceID -gt "0") { $InstallString = "$InstallString -DeviceID $DeviceID" } IF ($ServerID -gt "0") { $InstallString = "$InstallString -ServerID $ServerID" } IF ($InternalLicensing -gt "0") { $InstallString = "$InstallString -InternalLicensing $InternalLicensing" } IF ($CPLExchange -gt "0") { $InstallString = "$InstallString -CPLExchange $CPLExchange" } IF ($CPLLync -gt "0") { $InstallString = "$InstallString -CPLLync $CPLLync" } IF ($CPLOffice -gt "0") { $InstallString = "$InstallString -CPLOffice $CPLOffice" } IF ($CPLOS -gt "0") { $InstallString = "$InstallString -CPLOS $CPLOS" } IF ($CPLProject -gt "0") { $InstallString = "$InstallString -CPLProject $CPLProject" } IF ($CPLSSharepoint -gt "0") { $InstallString = "$InstallString -CPLSSharepoint $CPLSSharepoint" } IF ($CPLSQLServer -gt "0") { $InstallString = "$InstallString -CPLSQLServer $CPLSQLServer" } IF ($CPLVisio -gt "0") { $InstallString = "$InstallString -CPLVisio $CPLVisio" } IF ($CPLVS -gt "0") { $InstallString = "$InstallString -CPLVS $CPLVS" } IF ($Relay1 -gt "0") { $InstallString = "$InstallString -Relay1 $Relay1" } IF ($Relay2 -gt "0") { $InstallString = "$InstallString -Relay2 $Relay2" } IF ($LocalInstallDir -gt "0") { $InstallString = "$InstallString -LocalInstallDir $LocalInstallDir" } DPLog -Type INFO -Message "INSTALLING BES.." Invoke-Expression $InstallString } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL BES NOT DETECTED. SKIPPING." } # AWS # If the server is not detected as an AWS instance, skip this section IF ((((Get-WmiObject Win32_ComputerSystem).PrimaryOwnerName) -eq "Amazon") -or (((Get-WmiObject Win32_ComputerSystem).PrimaryOwnerName) -eq "EC2")) { DPLog -Type INFO -Message "AWS SERVER DETECTED. CHECKING IF AWS FUNCTIONS NEED TO BE RUN." # AWS Timezone IF (($xml.Variables.AWS.AutoSet.Timezone) -eq $true) { DPLog -Type INFO -Message "OPTION TO AUTOMATICALLY SET TIMEZONE BASED ON AWS LOCATION DETECTED." DPAWSSetTimezone } ELSE { DPLog -Type INFO -Message "OPTION TO AUTOMATICALLY SET TIMEZONE BASED ON AWS LOCATION NOT DETECTED. SKIPPING." } # AWS NTP IF (($xml.Variables.AWS.AutoSet.NTP) -eq $true) { DPLog -Type INFO -Message "OPTION TO AUTOMATICALLY SET NTP BASED ON AWS LOCATION DETECTED." DPAWSSetNTP } ELSE { DPLog -Type INFO -Message "OPTION TO AUTOMATICALLY SET NTP BASED ON AWS LOCATION NOT DETECTED. SKIPPING." } # AWS update EC2 tags Function UpdateTag( [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$False)] [string]$TagNum ) { IF ((($xml.Variables.AWS.UpdateEC2Tags.$TagNum.InstanceList) -gt "0") -and (($xml.Variables.AWS.UpdateEC2Tags.$TagNum.TagKey) -gt "0") -and (($xml.Variables.AWS.UpdateEC2Tags.$TagNum.TagValue) -gt "0")) { DPLog -Type INFO -Message "OPTION TO UPDATE EC2 TAG ($TagNum) DETECTED." DPAWSUpdateEC2Tag -InstanceList ($xml.Variables.AWS.UpdateEC2Tags.$TagNum.InstanceList) -TagKey ($xml.Variables.AWS.UpdateEC2Tags.$TagNum.TagKey) -TagValue ($xml.Variables.AWS.UpdateEC2Tags.$TagNum.TagValue) } ELSE { DPLog -Type INFO -Message "OPTION TO UPDATE EC2 TAG ($TagNum) NOT DETECTED. SKIPPING." } } UpdateTag -TagNum Tag1 UpdateTag -TagNum Tag2 UpdateTag -TagNum Tag3 UpdateTag -TagNum Tag4 UpdateTag -TagNum Tag5 UpdateTag -TagNum Tag6 UpdateTag -TagNum Tag7 UpdateTag -TagNum Tag8 # AWS apply SG ACL rules Function ApplyACL( [Parameter(Position=1, Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$False)] [string]$RuleNum ) { IF ((($xml.Variables.AWS.InboundSGACLRules.$RuleNum.InboundSG) -gt "0") -and (($xml.Variables.AWS.InboundSGACLRules.$RuleNum.SourceSG) -gt "0") -and (($xml.Variables.AWS.InboundSGACLRules.$RuleNum.PortObject) -gt "0")) { DPLog -Type INFO -Message "OPTION TO APPLY INBOUND SG ACL ($RuleNum)DETECTED." DPAWSApplyInboundSGACLRules -InboundSG ($xml.Variables.AWS.InboundSGACLRules.$RuleNum.InboundSG) -SourceSG ($xml.Variables.AWS.InboundSGACLRules.$RuleNum.SourceSG) -PortObject ($xml.Variables.AWS.InboundSGACLRules.$RuleNum.PortObject) } ELSE { DPLog -Type INFO -Message "OPTION TO APPLY INBOUND SG ACL ($RuleNum) NOT DETECTED. SKIPPING." } } ApplyACL -RuleNum Rule1 ApplyACL -RuleNum Rule2 ApplyACL -RuleNum Rule3 ApplyACL -RuleNum Rule4 ApplyACL -RuleNum Rule5 ApplyACL -RuleNum Rule6 } ELSE { DPLog -Type INFO -Message "AWS SERVER NOT DETECTED. SKIPPING AWS FUNCTIONS." } # Disable Automatic Updates IF (($xml.Variables.WindowsUpdates.DisableAutomaticUpdates) -eq $true) { DPLog -Type INFO -Message "OPTION TO DISABLE AUTOMATIC UPDATES DETECTED." DPDisableWindowsUpdateCheck } ELSE { DPLog -Type INFO -Message "OPTION TO DISABLE AUTOMATIC UPDATES NOT DETECTED. SKIPPING." } # Install Windows Updates IF (($xml.Variables.WindowsUpdates.InstallAfterSetup) -eq $true) { IF (($xml.Variables.WindowsUpdates.InstallOptional) -eq $true) { DPLog -Type INFO -Message "OPTION TO INSTALL WINDOWS UPDATES, INCLUDING OPTIONAL UPDATES DETECTED." DPInstallWindowsUpdates -InstallOptional Y # Remove Windows Update reboot flag, to allow the script to continue without rebooting. Reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f DPLog -Type INFO -Message "RUNNING WINDOWS UPDATE A SECOND TIME.." DPInstallWindowsUpdates -InstallOptional Y } ELSE { DPLog -Type INFO -Message "OPTION TO INSTALL WIDNOWS UPDATES, WITHOUT OPTIONAL UPDATES DETECTED." DPInstallWindowsUpdates # Remove Windows Update reboot flag, to allow the script to continue without rebooting. Reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f DPLog -Type INFO -Message "RUNNING WINDOWS UPDATE A SECOND TIME.." DPInstallWindowsUpdates } } ELSE { DPLog -Type INFO -Message "OPTION TO INSTAL WINDOWS UPDATES NOT DETECTED. SKIPPING." } # Run post config/pre reboot scripts Function RunPostconfigPreReboot( [Parameter(Position=1, Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)] [string]$PostConfigPreReboot ) { IF ($PostConfigPreReboot.EndsWith(".ps1")) { DPLog -Type INFO -Message "OPTION TO RUN A POST CONFIGURATION, PRE REBOOT PS1 SCRIPT DETECTED. RUNNING: $PostConfigPreReboot." Invoke-Expression $PostConfigPreReboot } IF (($PostConfigPreReboot.EndsWith(".bat")) -or ($PostConfigPreReboot.EndsWith(".cmd"))) { DPLog -Type INFO -Message "OPTION TO RUN A POST CONFIGURATION, PRE REBOOT BATCH SCRIPT DETECTED. RUNNING: $PostConfigPreReboot." cmd.exe /c $PreConfig } IF ($PostConfigPreReboot.EndsWith(".exe")) { DPLog -Type INFO -Message "OPTION TO RUN A POST CONFIGURATION, PRE REBOOT EXECUTABLE DETECTED. RUNNING: $PostConfigPreReboot." Start-Process $PostConfigPreReboot -Wait } } RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.PSScript1) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.PSScript2) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.PSScript3) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.PSScript4) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.Batch1) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.Batch2) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.Batch3) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.Batch4) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.EXE1) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.EXE2) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.EXE3) RunPostconfigPreReboot ($xml.Variables.PostConfiguration.PreReboot.EXE4) # Set post config/post reboot command IF ($xml.Variables.PostConfiguration.PostReboot.PSCommand -gt "0") { $Command = $xml.Variables.PostConfiguration.PostReboot.PSCommand DPLog -Type INFO -Message "OPTION TO RUN A POST CONFIGURATION, POST REBOOT PS1 COMMAND DETECTED. ADDING AUTORUN: $xml.Variables.PostConfiguration.PostReboot.Command." DPAddAutoResumeNoLogon -Username $xml.Variables.PostConfiguration.PostReboot.Username -Password $xml.Variables.PostConfiguration.PostReboot.Password -Command "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe $Command" } # Rename/Join Domain IF (($xml.Variables.General.ServerName) -gt "0") { IF ((($xml.Variables.Domain.Name) -gt "0") -and (($xml.Variables.Domain.Username) -gt "0") -and (($xml.Variables.Domain.Password) -gt "0")) { # Check if the server needs to be renamed and joined IF ($Hostname -ne (hostname)) { IF ($xml.Variables.Domain.OU -gt "0") { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER AND JOIN THE DOMAIN WITH A SPECIFIED OU DETECTED." DPJoinDomain -DomainName $xml.Variables.Domain.Name -ADUsername $xml.Variables.Domain.Username -ADPassword $xml.Variables.Domain.Password -OUPath $xml.Variables.Domain.OU -NewName $xml.Variables.General.ServerName } ELSE { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER AND JOIN THE DOMAIN WITHOUT A SPECIFIED OU DETECTED." DPJoinDomain -DomainName $xml.Variables.Domain.Name -ADUsername $xml.Variables.Domain.Username -ADPassword $xml.Variables.Domain.Password -NewName $xml.Variables.General.ServerName } } ELSE { IF ($xml.Variables.Domain.OU -gt "0") { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER AND JOIN THE DOMAIN WITH A SPECIFIED OU DETECTED. HOSTNAME IS ALREADY CORRECT" DPJoinDomain -DomainName $xml.Variables.Domain.Name -ADUsername $xml.Variables.Domain.Username -ADPassword $xml.Variables.Domain.Password -OUPath $xml.Variables.Domain.OU } ELSE { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER AND JOIN THE DOMAIN WITHOUT A SPECIFIED OU DETECTED." DPJoinDomain -DomainName $xml.Variables.Domain.Name -ADUsername $xml.Variables.Domain.Username -ADPassword $xml.Variables.Domain.Password } } } ELSE { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER WITHOUT JOINING A DOMAIN DETECTED." DPRenameServer -ServerName $xml.Variables.General.ServerName } } ELSE { DPLog -Type INFO -Message "OPTION TO RENAME THE SERVER NOT DETECTED. SKIPPING." IF ((($xml.Variables.Domain.Name) -gt "0") -and (($xml.Variables.Domain.Username) -gt "0") -and (($xml.Variables.Domain.Password) -gt "0")) { DPLog -Type INFO -Message "OPTION TO JOIN THE DOMAIN DETECTED." DPJoinDomain -DomainName $xml.Variables.Domain.Name -ADUsername $xml.Variables.Domain.Username -ADPassword $xml.Variables.Domain.Password -OUPath $xml.Variables.Domain.OU } ELSE { DPLog -Type INFO -Message "OPTION TO JOIN THE DOMAIN NOT DETECTED. SKIPPING." } } # If a script will not run on reboot, set the progress key to complete. IF ($xml.Variables.PostConfiguration.PostReboot.PSCommand -lt "0") { REG ADD HKLM\SOFTWARE\Datapipe\AutomatedServerSetup /v WindowsPostConfigStatus /t REG_SZ /d InProgress /f | Out-Null } # Prompt user IF (($xml.Variables.AutomationSettings.UnattendedSetup) -ne $true) { # Warn user a reboot is required and wait $a = new-object -comobject wscript.shell $intAnswer = $a.popup("SETUP COMPLETE!.`r`nREMINDERS:`r`n1. If this is a physical server, please run the applicable support/driver pack.`r`n2. If this server needs to be joined to the domain please do so AFTER the server reboots.`r`n3. If requested, please make sure backups and monitoring are setup. This server must be rebooted to complete the setup.`r`nPress OK to reboot.", ` 0,"COMPLETE - REBOOT REQUIRED",0) } ELSE { # Reboot IF (($xml.Variables.AutomationSettings.AutomaticReboots) -eq $true) { Restart-Computer -Force } }