########## BEGIN SCRIPT HEADER ########## # DATAPIPE MCD 2012 R2 SQL AUTOMATION - SPIN UP SERVER FROM AMI # Author: Anthony Marino # Version = "1.0.3" # 10/27/2014" ########## END SCRIPT HEADER ########## ##### DO NOT EDIT ##### Param( $Step, $ServerName, $IPAddress, $DNS1, $DNS2, $WinClusterIPList, $WinNodesList, $WSFCName, $AddToCluster ) ##### DO NOT EDIT ##### IF (($Step) -eq "1") { # Import the Windows PSM Import-Module C:\DPAutomation\DPWindowsPSM-MCD.psm1 -Force Invoke-WebRequest -Uri "https://toolkit.datapipe.net/bestasks/justin/dpsqlawspostami.psm1" -OutFile "C:\DPAutomation\dpsqlawspostami.psm1" # Write parameters to XML $XML = [XML](Get-Content "C:\DPAutomation\Variables.xml") $XML.Variables.Windows."ServerName" = $ServerName $XML.Variables.Windows."IPAddress" = $IPAddress $XML.Variables.Windows."DNS1" = $DNS1 $XML.Variables.Windows."DNS2" = $DNS2 $XML.Save("C:\DPAutomation\Variables.xml") $XML = [XML](Get-Content "C:\DPAutomation\Variables.xml") # Setup the server DPRenameAdminToDpadmin DPSetDNSServers -BaseIP $XML.Variables.Windows.IPAddress -DNS1 $XML.Variables.Windows.DNS1 -DNS2 $XML.Variables.Windows.DNS2 DPConfigDNSSuffix DPAWSSetTimezone -Log Y DPRenameServer -ServerName $XML.Variables.Windows.Servername # Remove and set autoresume DPRemoveAutoResumeNoLogon DPAddAutoResumeNoLogon -Command "powershell C:\DPAutomation\DPW2K12R2-NewSQLServer-MCD.ps1 -Step 2" # Reboot Restart-Computer -Force } IF (($Step) -eq "2") { # Import the Windows PSM Import-Module C:\DPAutomation\DPWindowsPSM-MCD.psm1 -Force # Import XML $XML = [XML](Get-Content "C:\DPAutomation\Variables.xml") # Join the domain $DomainName = $XML.Variables.Domain.DomainName $ADUsername = $XML.Variables.Domain.ADUsername $ADPassword = $XML.Variables.Domain.ADPassword DPJoinDomain -DomainName $DomainName -ADUsername $ADUsername -ADPassword $ADPassword -Log Y # Remove and set autoresume DPRemoveAutoResumeNoLogon DPAddAutoResumeNoLogon -Command "powershell C:\DPAutomation\DPW2K12R2-NewSQLServer-MCD.ps1 -Step 3" # Reboot Restart-Computer -Force } IF (($Step) -eq "3") { # Import the Windows PSM Import-Module C:\DPAutomation\DPWindowsPSM-MCD.psm1 -Force # Import XML $XML = [XML](Get-Content "C:\DPAutomation\Variables.xml") # Continue server setup DPDisableWindowsFW # Remove and set autoresume DPRemoveAutoResumeNoLogon DPAddAutoResumeNoLogon -Command "powershell C:\DPAutomation\DPW2K12R2-NewSQLServer-MCD.ps1 -Step 4" -Username $XML.Variables.Domain.ADUsername -Password $XML.Variables.Domain.ADPassword Restart-Computer -Force } IF (($Step) -eq "4") { # Import the Windows PSM Import-Module C:\DPAutomation\DPWindowsPSM-MCD.psm1 -Force Import-Module C:\DPAutomation\DPSQLAWSPostAMI.psm1 -Force # Remove and set autoresume DPRemoveAutoResumeNoLogon # Import XML $XML = [XML](Get-Content "C:\DPAutomation\Variables.xml") $isopath = $xml.Variables.SQL.Install.IsoPath DPAddAutoResumeNoLogon -Command "powershell C:\DPAutomation\DPW2K12R2-NewSQLServer-MCD.ps1 -Step 5" -Username $XML.Variables.Domain.ADUsername -Password $XML.Variables.Domain.ADPassword #Setup Node Mount-DiskImage -ImagePath $isoPath; $MountLetter = (Get-DiskImage -ImagePath $isoPath | Get-Volume).driveletter $cmd = $MountLetter + ":\setup.exe" & $cmd /configurationfile="c:\DPAutomation\SQLInstallConfiguration.ini" /IACCEPTSQLSERVERLICENSETERMS Dismount-DiskImage -ImagePath $isoPath #New-WindowsAdministrator -User $xml.Variables.RedGate.Install.RedGateServiceAccount New-SQLSYSADMIN -User $xml.Variables.RedGate.Install.RedGateServiceAccount InstallRedGate -RedGateServiceAccount $xml.Variables.RedGate.Install.RedGateServiceAccount -RedGateServicePassword $XML.Variables.RedGate.Install.RedGateServicePassword #InstallFailoverClusterFeature #Setup Cluster if ($AddToCluster = "Yes") { setupfailoverclusterinstance -Nodes $WinNodesList -WindowsFciIP $WinClusterIPList -WindowsFciName $WSFCName } Restart-Computer -Force } IF (($Step) -eq "5") { # Import the Windows PSM Import-Module C:\DPAutomation\DPWindowsPSM-MCD.psm1 -Force Import-Module C:\DPAutomation\DPSQLAWSPostAMI.psm1 -Force # Remove autoresume DPRemoveAutoResumeNoLogon if ($AddToCluster = "Yes") { import-module sqlps DPEnableSQLAlwaysOnAllNodes -Nodes $WinNodesList } # Add security legal notice $Message = "IMPORTING AND ENABLING LEGAL NOTICE MESSAGES." DPLOG -type INFO -Message $Message Write-Host $Message $legalnoticecaption = Get-Content C:\DPAutomation\legalnoticecaption.txt $legalnoticetext = Get-Content C:\DPAutomation\legalnoticetext.txt Set-ItemProperty "hklm:\\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system" -Name legalnoticecaption -Value $legalnoticecaption Set-ItemProperty "hklm:\\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system" -Name legalnoticetext -Value $legalnoticetext }