2012 PowerShell Install
2012 install
<#
.SYNOPSIS
The purpose of this script is to gather details from the DBA installer to customize their SQL Server install. This script will produce a
configuration ini file and will launch a SQL Server silent Install. After the silent instal, a basic check is done to ensure the new instance
is created. If the new instance exists, the port number is changed from dynamic to static, firewall rules are updated with the new port information,
sa account is disabled, and the polkj11 account is created.
.DESCRIPTION
This script will gather the following information:
1.) Named or Default instance
2.) SQL Server Service Account Name
3.) SQL Server Service Account Password
4.) SQL Agent Service Account Name
5.) SQL Agent Service Account Password
6.) Integrated SErvices Service Account Name
7.) Integrated Service Service Account Password
8.) Alternate SA account Name
9.) SA / Alternate SA Password
10.) DBA Privileged Group -- See variable below for list of groups
.NOTES
File Name : EDMSQLServer2012_Install.ps1
Company : Wells Fargo
Dept : CTD Enterprise Data Management
Author : John Aspenleiter - jaspenle@wellsfargo.com
Requires : The script must be run as Administrator, and access to the following nas shares so media can be copied locally
OXMOOR \\wfsaloxnsf01\DAN_BWB_SOFT_01
SV2 \\mns2nsf701z1.wellsfargo.net\dan_pwv_soft_01
TEMPE \\azt2nsf701z1.wellsfargo.net\dan_bwz_soft_01
SILAS \\wfsncsilsnsf02\DAN_PWS_SOFT_01
STL \\wfsmotemrnnf02\DAN_PWL_SOFT_01
WEC \\wfsncwecnnf01\DAN_PWW_SOFT_01
Create Date: 3/9/2013
.LINK
N/A
.EXAMPLE
.INPUTTYPE
.RETURNVALUE
A configuration ini file is created and placed on local drive. A silent install is then kicked off.
.REVISION HISTORY
Version : 1.0.0
Date : 4/26/2013
Author : John Aspenleiter
Description: The script was first developed on 3/9/2013, the final version used for the first release
is this date. All future releases will be subject to version control.
Version : 1.1.0
Date : 5/10/2013
Author : John Aspenleiter
Description: Added the following enhancements:
1. Displays port information to the end user.
2. Added Standard / Enterprise edition support - new form to choose from.
3. Drive selection supports mount points.
4. Drive selection form now shows the exact install paths
5. SSIS checkbox - you now have the option to install SSIS.
6. Deployment of EAM objects for EDM's login provisioning workflow.
Version : 1.1.1
Date : 7/15/2013
Author : John Aspenleiter
Description: BUG FIX - Error found when installing to a server where there is only a C drive present.
Found an elseif not capturing the c drive correctly. In the "getdriveinfo" function,
I changed the elseif from:
ElseIf ($rootdrive -eq "C:\")
TO
ElseIf ($rootdrive -eq "C:")
Version : 1.2.0
Date : 8/16/2013
Author : Brent Johnston
Description: ENHANCEMENT - Commented out the EAM object deployments because that will no longer be
part of the install package
Version : 1.2.1
Date : 4/17/2014
Author : Brent Johnston
Description: BUG FIX - Fixing variable scoping issue discovered during Windows 2012 testing
Version : 1.2.3 & 1.2.4
Date : 12/09/2015 & 5/26/2015
Author : J Aspenleiter
Description: Updating NAS filer location for where install media is stored.
Version : 1.2.5
Date : 11/25/2015
Author : J. Aspenleiter
Description: Updated -- $stl_nas = "wfsmotemrnnf02.bank.corp"
$wec_nas = "wfsncwecnnf01.bank.corp"
For some reason, ent.wfb.bank.corp stopped working - not gonna look into it much....
Updated the GPO check with the correct GPO names that should be used.
CPS_CORP_SQL_2008_2012_2014
CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide
Version : 1.2.6
Date : 05/20/2016
Author : D. Leone
Description: Updated - included new privilegd groups based on LOB and Environment:
LOB Env Domain ADGroupName
DVE PRD AD-ENT PRV_EDM_FA_SRV_DVE_SA_PRD
DVE NONPRD AD-ENT PRV_EDM_FA_SRV_DVE_SA_NONPRD
CorpTech PRD AD-ENT PRV_EDM_FA_SRV_CorpTech_SA_PRD
CorpTech NP AD-ENT PRV_EDM_FA_SRV_CorpTech_SA_NP
CommBank PRD AD-ENT PRV_EDM_FA_SRV_CommBank_SA_PRD
CommBank NP AD-ENT PRV_EDM_FA_SRV_CommBank_SA_NP
Lending PRD AD-ENT PRV_EDM_FA_SRV_Lending_SA_PRD
Lending NP AD-ENT PRV_EDM_FA_SRV_Lending_SA_NP
WIM PRD AD-ENT PRV_EDM_FA_SRV_WIM_SA_PRD
WIM NP AD-ENT PRV_EDM_FA_SRV_WIM_SA_NP
ALL ALL ALL PRV_EDM_FA_SRV_SQLServiceAccounts
DVE, CommBank ALL ALL PRV_EDM_DA_SRV_COMMBKGDBAdmins
DVE, CorpTech ALL ALL PRV_EDM_DA_SRV_CTFHDBADMINS
DVE ALL ALL PRV_EDM_DA_SRV_DANDBADMINS
DVE, WIM ALL ALL PRV_EDM_DA_SRV_WFADBADMINS
DVE, Lending ALL ALL PRV_EDM_DA_SRV_LENDINGDBADMINS
ALL ALL ALL PRV_EDM_DA_SRV_WFISDBAdmins
#>
clear
#Let's also clear out ANY errors that may have been passed from the console to the scirpt.
If($Error){$Error.Clear()}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#ACTIVE DIRECTORY DOMAIN
Set-Variable -Name AD_Domain -Value (Get-Content env:UserDomain) -Scope Script
#INSTALL DRIVE LETTER
Set-Variable -Name Install_Drive -Scope Script
#DATA DRIVE LETTER
Set-Variable -Name Data_Drive -Scope Script
#DEFAULT INSTALL PATH - for both binaries, and data... For DATA PATH - mount points will override this default path if chosen.
Set-Variable -Name Default_SQL_Path -Value "\Program Files\Microsoft SQL Server" -Scope Script
#DEFAULT WOW DIR
Set-Variable -Name Default_Wow_Path -Value "\Program Files (x86)\Microsoft SQL Server" -Scope Script
#SQLADMIN Folder Admin Path (ROOT FOLDER)
Set-Variable -Name SQLAdmin_Folder -Value "SQLAdmin" -Scope Script
#EDMAUTO Folder
Set-Variable -Name EDMAuto_Folder -Value "EDMAuto" -Scope Script
#INSTALL media Folder: - this is now being set in the Getedition Function
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script
#UpdateSource media Folder:
Set-Variable -Name SS_UpdateSource_Folder -Value "Media\SQL2012UpdateSource" -Scope Script
#config Folder:
Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#config file path: - this is now being set in the GetEdition Function
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2012 Installation" -Scope Script
#Centralized Log File Path:
Set-Variable -Name CntrlLogPath -Value "\\wfsmotemrnnf02\DAN_PWL_SOFT_01\EDMSqlSvrInstall\Logs\" -Scope Script
#TimsStamp for log file
Set-Variable -Name datetimestamp -Value (Get-Date -uformat %Y%m%d%H%M%S) -Scope Script
#Log File Prefix Name:
Set-Variable -Name LogFilePrefix -Value "SqlSvr2012" -Scope Script
Set-Variable -Name MediaLogFile -Value $CntrlLogPath$LogFilePrefix"_MediaCopy_"$datetimestamp".txt" -Scope Script
Set-Variable -Name InstallLogFile -Value $CntrlLogPath$LogFilePrefix"_Install_"$datetimestamp".txt" -Scope Script
Set-Variable -Name MessageStamp -Value "$(Get-Date -format 'u')`r`n$([Environment]::UserName)`r`n$([Environment]::UserDomainName)`r`n$([Environment]::MachineName)`r`n`r`n" -Scope Script
Set-Variable -Name LogMessage -Value $MessageStamp -Scope Script
Set-Variable -Name MinSupportRelease -Value "R11" -Scope Script
#Setting the Array for all the Previleged Groups we currently allow.
$PREV_Options = `
@(`
"AD-ENT\PRV_EDM_FA_SRV_SQLServiceAccounts"`
,"AD-ENT\PRV_EDM_DA_SRV_COMMBKGDBAdmins"`
,"AD-ENT\PRV_EDM_DA_SRV_CTFHDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_DANDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_TISOPSDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_WFADBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_LENDINGDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_WFISDBAdmins"`
,"AD-ENT\PRV_EDM_DA_SRV_DASDBAdmins"`
,"AD-ENT\DTCS_EBS_EDM_SQL"`
)
#Setting the Array for the alternative SA accounts that EDM supports - setting this to an array to support multiple choices:
$SA_Options = `
@(`
"polkj11"`
)
#LOBS to determine what groups
[array]$LOBS = "DVE", "CorpTech", "CommBank", "Lending","WIM"
#LOBS to determine what groups
[array]$Environments = "PROD", "NON-PROD"
$LOBChoice = "DVE"
$EnvChoice = "PROD"
################ MEDIA LOCATIONS #########################
<#
OXMOOR \\aloxnsf701z1.wellsfargo.net\DAN_BWB_SOFT_01
SV2 \\mns2nsf701z1.wellsfargo.net\dan_pwv_soft_01
TEMPE \\azt2nsf701z1.wellsfargo.net\dan_bwz_soft_01
SILAS \\ncslnsf701z1.wellsfargo.net\DAN_PWS_SOFT_01
STL \\wfsmotemrnnf02.bank.corp\DAN_PWL_SOFT_01
WEC \\wfsncwecnnf01.bank.corp\DAN_PWW_SOFT_01
##############Message Box Values######################
0: OK
1: OK Cancel
2: Abort Retry Ignore
3: Yes No Cancel
4: Yes No
5: Retry Cancel
#>
$oxmoor_nas = "aloxnsf701z1.wellsfargo.net"
$sv2_nas = "mns2nsf701z1.wellsfargo.net"
$tempe_nas = "azt2nsf701z1.wellsfargo.net"
$silas_nas = "ncslnsf701z1.wellsfargo.net"
$stl_nas = "wfsmotemrnnf02.bank.corp"
$wec_nas = "wfsncwecnnf01.bank.corp"
$oxmoor_path = "\\$oxmoor_nas\DAN_BWB_SOFT_01\"
$sv2_path = "\\$sv2_nas\dan_pwv_soft_01\"
$tempe_path = "\\$tempe_nas\dan_bwz_soft_01\"
$silas_path = "\\$silas_nas\DAN_PWS_SOFT_01\"
$stl_path = "\\$stl_nas\DAN_PWL_SOFT_01\"
$wec_path = "\\$wec_nas\DAN_PWW_SOFT_01\"
################ MEDIA LOCATIONS #########################
#set a local script variable to the name of the server we're installing on.
Set-Variable -Name hostname -Scope Script
$hostname = Get-Content env:computername
#FUNCTIONS BEGIN
Function GetLobEnvironment
{
#This came as an after thought - so, we're adding it as it's own form since too many variables are dependant on this...
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2014EE" -Scope Script - ENTERPRISE EDITON
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2014SE" -Scope Script - STANDARD EDITON
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2014 Installation" -Scope Script
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SQL Server LOB & Environment Selection"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
$script:LOBInstall = $objListLOBDropDown.SelectedItem
$script:EnvInstall = $objListEnvDropDown.SelectedItem
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
<#
$objEdtnLbl = New-Object System.Windows.Forms.Label
$objEdtnLbl.Location = New-Object System.Drawing.Size(10,20)
$objEdtnLbl.autosize = $true
$objEdtnLbl.Text = "Please select the edition of SQL Server 2014 you wish to install."
$objForm.Controls.Add($objEdtnLbl)
$objEdtnListBox = New-Object System.Windows.Forms.ListBox
$objEdtnListBox.Location = New-Object System.Drawing.Point(10,40)
$objEdtnListBox.Size = New-Object System.Drawing.Size(150,50)
$objEdtnListBox.Items.add("ENTERPRISE EDITION")
$objEdtnListBox.Items.add("STANDARD EDITION")
$objEdtnListBox.tabindex = 0
$objEdtnListBox.SetSelected(0,$true)
$objForm.Controls.Add($objEdtnListBox)
#>
#CREATE THE LABEL
#$y+=30
$objLbl_10 = New-Object System.Windows.Forms.Label
$objLbl_10.Location = New-Object System.Drawing.Size(10,40) #(0,$y)
$objLbl_10.Autosize = $true
$objLbl_10.Text = "LOB:"
$objForm.Controls.Add($objLbl_10)
$objLbl_11 = New-Object System.Windows.Forms.Label
$objLbl_11.Location = New-Object System.Drawing.Size(150,40) #(150,$y)
$objLbl_11.Autosize = $true
$objLbl_11.Text = "Environment:"
$objForm.Controls.Add($objLbl_11)
#Create the select Boxes
$objListLOBDropDown = new-object System.Windows.Forms.ComboBox
$objListLOBDropDown.Location = new-object System.Drawing.Point(10,60)
$objListLOBDropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($LOB in $LOBS) {
[void] $objListLOBDropDown.Items.Add($LOB)
}
$objListLOBDropDown.SelectedIndex = $LOBS.IndexOf($LOBChoice)
$objForm.Controls.Add($objListLOBDropDown)
$objListEnvDropDown = new-object System.Windows.Forms.ComboBox
$objListEnvDropDown.Location = new-object System.Drawing.Point(150,60)
$objListEnvDropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($Environ in $Environments) {
[void] $objListEnvDropDown.Items.Add($Environ)
}
$objListEnvDropDown.SelectedIndex = $Environments.IndexOf($EnvChoice)
$objForm.Controls.Add($objListEnvDropDown)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
If (!$exit) # -and $SS_Setup_Folder)
{
#Set-Variable -Name SS_Setup_Folder -Value $SS_Setup_Folder -Scope Script
#Set-Variable -Name Form_Name -Value $Form_Name -Scope Script
Return $true
}
Else
{
Exit
}
}
Function GetEdition
{
#This came as an after thought - so, we're adding it as it's own form since too many variables are dependant on this...
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script - ENTERPRISE EDITON
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012SE" -Scope Script - STANDARD EDITON
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2012 Installation" -Scope Script
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SQL Server Edition Selection"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
If ($objEdtnListBox.SelectedItem.ToString() -eq "ENTERPRISE EDITION")
{
$script:SS_Setup_Folder = "Media\SQL2012EE"
$script:Form_Name = "EDM SQL Server 2012 Enterprise Edition Installation"
}
Else
{
$script:SS_Setup_Folder = "Media\SQL2012SE"
$script:Form_Name = "EDM SQL Server 2012 Standard Edition Installation"
}
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objEdtnLbl = New-Object System.Windows.Forms.Label
$objEdtnLbl.Location = New-Object System.Drawing.Size(10,20)
$objEdtnLbl.autosize = $true
$objEdtnLbl.Text = "Please select the edition of SQL Server 2012 you wish to install."
$objForm.Controls.Add($objEdtnLbl)
$objEdtnListBox = New-Object System.Windows.Forms.ListBox
$objEdtnListBox.Location = New-Object System.Drawing.Point(10,40)
$objEdtnListBox.Size = New-Object System.Drawing.Size(150,50)
$objEdtnListBox.Items.add("ENTERPRISE EDITION")
$objEdtnListBox.Items.add("STANDARD EDITION")
$objEdtnListBox.tabindex = 0
$objEdtnListBox.SetSelected(0,$true)
$objForm.Controls.Add($objEdtnListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
If (!$exit -and $SS_Setup_Folder)
{
Set-Variable -Name SS_Setup_Folder -Value $SS_Setup_Folder -Scope Script
Set-Variable -Name Form_Name -Value $Form_Name -Scope Script
Return $true
}
Else
{
Exit
}
}
Function GetRelease
{
[int]$minInt = $MinSupportRelease.Replace("R","")
$IsSupported = $true
If (Test-Path "HKLM:\SOFTWARE\AutoBuild")
{
$Release = (Get-Item -Path "hklm:\SOFTWARE\AutoBuild").GetValue("AutoBuildVersion")
$ReleaseInt = ($Release.split("."))[0]
If ($ReleaseInt.StartsWith("R"))
{
#Ok we can test it - it starts with a R, if it doesn't, it's probably an SSO - which is not supported.
[int]$ReleaseInt = $ReleaseInt.Replace("R","")
If ([int]$ReleaseInt -lt [int]$minInt )
{
$IsSupported = $false
}
}
Else
{
$IsSupported = $false
}
}
Else
{
$Release = "UNKNOWN"
}
New-Object PSObject -Property @{
Version = [string]$Release;
IsSupported = [bool]$IsSupported
}
}
Function GetDriveInfo
{
#get all drives available on the system that have over 1 GB free
$drives = Get-WmiObject -Class Win32_Volume | Where-Object {$_.FreeSpace -gt 1073741824}
Foreach ($drive in $drives)
{
$rootdrive = ($drive.Caption).TrimEnd("\")
If ($rootdrive -ne "C:" -and $AvailDrives -notlike "*$rootdrive*" )
{
#We only want drives that are not the C drive, and we don't want duplicates...
#When you grab a list of drives from the volume class, you may get multiples of the same
#drive due to mount points.
If(!$AvailDrives){$AvailDrives = $rootdrive}
Else {$AvailDrives += ","+$rootdrive}
}
ElseIf ($rootdrive -eq "C:")
{
$AvailDrive = $rootdrive
}
}
#We need to see if there is a previous installation of SQL Server - if so, we need to pick the drive that already has the
#binaries - they don't have an option now....
If (Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup")
{
$installDrive = (((Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup").GetValue("SQLPath")).Split("\"))[0]
}
#CREATE THE DRIVE FORM:
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SELECT DRIVES AND/OR MOUNT POINTS"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(125,400)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
$script:Install_Drive=$objBinListBox.SelectedItem.ToString()
;$script:Data_Drive=$objDataListBox.SelectedItem.ToString()
;$script:InstallSqlPath=$objBinListBox.SelectedItem+$Default_SQL_Path
;$script:InstallWowPath=$objBinListBox.SelectedItem+$Default_Wow_Path
;If ($($objDataListBox.SelectedItem).Length -lt 3)
{
$script:InstallDataPath = $objDataListBox.SelectedItem+$Default_SQL_Path
}
Else
{
$script:InstallDataPath = $objDataListBox.SelectedItem
}
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(220,400)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objBinListBox = New-Object System.Windows.Forms.ListBox
$objBinListBox.Location = New-Object System.Drawing.Point(10,40)
$objBinListBox.Size = New-Object System.Drawing.Size(300,80)
$objBinListBox.Add_Click({
$objBinDisplayOut.Text = $objBinListBox.SelectedItem+$Default_SQL_Path;
$objWowDisplayOut.Text = $objBinListBox.SelectedItem+$Default_Wow_Path
})
$objBinListBox.tabindex = 0
#DEFAULT INSTALL PATH - for both binaries, and data... For DATA PATH - mount points will override this default path if chosen.
#Set-Variable -Name Default_SQL_Path -Value "\Program Files\Microsoft SQL Server" -Scope Script
#DEFAULT WOW DIR
#Set-Variable -Name Default_Wow_Path -Value "\Program Files (x86)\Microsoft SQL Server" -Scope Script
#"INSTANCEDIR=`"$Install_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSQLDATADIR=`"$Data_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSHAREDDIR=`"$Install_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSHAREDWOWDIR=`"$Install_Drive\Program Files (x86)\Microsoft SQL Server`"`r`n"+
If ($installDrive)
{
#We found that there is already an install of sql server, we're going to use the exact same binary drive as before.
$objBinListBox.Items.add($installDrive) | Out-Null
}
Else
{
If ($AvailDrives)
{
foreach($AvailDrive in $AvailDrives.Split(","))
{
$objBinListBox.Items.add($AvailDrive) | Out-Null
}
}
Else
{
$objBinListBox.Items.add($AvailDrive) | Out-Null
}
}
$objBinListBox.SetSelected(0,$true)
$objForm.Controls.Add($objBinListBox)
$objBinDisplay = New-Object System.Windows.Forms.Label
$objBinDisplay.Location = New-Object System.Drawing.Size(10,230)
$objBinDisplay.autosize = $true
$objBinDisplay.Text = "INSTALLING SHARED BINARIES TO:"
$objForm.Controls.Add($objBinDisplay)
$objBinDisplayOut = New-Object System.Windows.Forms.Label
$objBinDisplayOut.Location = New-Object System.Drawing.Size(20,250)
$objBinDisplayOut.autosize = $true
$objBinDisplayOut.Text = $objBinListBox.SelectedItem+$Default_SQL_Path
$objForm.Controls.Add($objBinDisplayOut)
$objWowDisplay = New-Object System.Windows.Forms.Label
$objWowDisplay.Location = New-Object System.Drawing.Size(10,270)
$objWowDisplay.autosize = $true
$objWowDisplay.Text = "INSTALLING SHARED WOW BINARIES TO ROOT PATH:"
$objForm.Controls.Add($objWowDisplay)
$objWowDisplayOut = New-Object System.Windows.Forms.Label
$objWowDisplayOut.Location = New-Object System.Drawing.Size(20,290)
$objWowDisplayOut.autosize = $true
$objWowDisplayOut.Text = $objBinListBox.SelectedItem+$Default_Wow_Path
$objForm.Controls.Add($objWowDisplayOut)
$objBinLabel = New-Object System.Windows.Forms.Label
$objBinLabel.Location = New-Object System.Drawing.Size(10,20)
#$objBinLabel.Size = New-Object System.Drawing.Size(380,20)
$objBinLabel.Autosize = $true
$objBinLabel.Text = "Select the drive or mount point you wish to install binaries and shared components:"
$objForm.Controls.Add($objBinLabel)
$objDataListBox = New-Object System.Windows.Forms.ListBox
$objDataListBox.Location = New-Object System.Drawing.Point(10,140)
$objDataListBox.Size = New-Object System.Drawing.Size(300,80)
$objDataListBox.Add_Click({
If ($($objDataListBox.SelectedItem).Length -lt 3)
{
$script:dataInstallPath = $objDataListBox.SelectedItem+$Default_SQL_Path
}
Else
{
$script:dataInstallPath = $objDataListBox.SelectedItem
};$objDataDisplayOut.Text = $dataInstallPath
})
$objDataListBox.tabindex = 1
If ($AvailDrives)
{
foreach($AvailDrive in $AvailDrives.Split(","))
{
$objDataListBox.Items.add($AvailDrive) | Out-Null
}
}
Else
{
$objDataListBox.Items.add($AvailDrive) | Out-Null
}
$objDataListBox.SetSelected(0,$true)
$objForm.Controls.Add($objDataListBox)
$objDataDisplay = New-Object System.Windows.Forms.Label
$objDataDisplay.Location = New-Object System.Drawing.Size(10,320)
$objDataDisplay.autosize = $true
$objDataDisplay.Text = "INSTALLING SYSTEM DATABASE FILES TO ROOT PATH:"
$objForm.Controls.Add($objDataDisplay)
$objDataDisplayOut = New-Object System.Windows.Forms.Label
$objDataDisplayOut.Location = New-Object System.Drawing.Size(20,340)
$objDataDisplayOut.autosize = $true
$data_selected_item = $objDataListBox.SelectedItem
If ([int]$data_selected_item.Lenth -lt 3)
{
$script:dataInstallPath = $data_selected_item+$Default_SQL_Path
}
Else
{
$script:dataInstallPath = $data_selected_item
}
$objDataDisplayOut.Text = $dataInstallPath
$objForm.Controls.Add($objDataDisplayOut)
$objDataLabel = New-Object System.Windows.Forms.Label
$objDataLabel.Location = New-Object System.Drawing.Size(10,120)
$objDataLabel.Size = New-Object System.Drawing.Size(380,20)
$objDataLabel.Text = "Select the drive or mount point you wish to install SYSTEM DATA files to:"
$objForm.Controls.Add($objDataLabel)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#if variables aren't set, then they must have pressed the X button on the form.
if (!$Install_Drive -or !$Data_Drive){exit}
if ($Install_Drive -and $Data_Drive)
{
Set-Variable -Name Install_Drive -value $Install_Drive -Scope Script
Set-Variable -Name Data_Drive -Value $Data_Drive -Scope Script
Set-Variable -Name InstallSqlPath -Value $InstallSqlPath -Scope Script
Set-Variable -Name InstallWowPath -Value $InstallWowPath -Scope Script
Set-Variable -Name InstallDataPath -Value $InstallDataPath -Scope Script
$true
}
}
Function GetMedia
{
<#
If this function is called, it's been detected that a local copy of the media doesn't exist.
The purpose of this function is to ping each NAS filer and detect the least amount of response time. This will
decide which NAS filer to use copying the media down. If the local folders are not created yet, we will create them for you
and then copy down the required media to install SQL Server.
#>
$nas_hosts = @($oxmoor_nas,$sv2_nas,$tempe_nas,$silas_nas,$stl_nas,$wec_nas)
$nas_paths = @($oxmoor_path,$sv2_path,$tempe_path,$silas_path,$stl_path,$wec_path)
foreach ($nas_host in $nas_hosts)
{
[string]$ResponsetimeTEST = (Test-Connection $nas_host -Count 1).ResponseTime
If (!$response_time)
{
[string]$response_time = [string]$ResponsetimeTEST
$NASHOST = $nas_host
}
else
{
If ([string]$ResponsetimeTEST -lt [string]$response_time)
{
[string]$response_time = [string]$ResponsetimeTEST
$NASHOST = $nas_host
}
}
}
Foreach ($nas_path in $nas_paths)
{
If ($NASHOST -eq $nas_path.split("\")[2])
{
$NAS_COPY_FROM = $nas_path
}
}
#Create the objects that do the copy - I picked these objects to do the copy to show progress to the installer.
$FOF_CREATEPROGRESSDLG = "&H0&"
$objShell = New-Object -ComObject "Shell.Application"
#copied these variable definitions here to help understand which each one means... Leaving here for future work.
# $SQLAdmin_Path = $Install_Drive+"\"+$SQLAdmin_Folder
# $EDMAuto_Path = $SQLAdmin_Path+"\"+$EDMAuto_Folder
# $InstallMedia_Path = $EDMAuto_Path+"\"+$SS_Setup_Folder
# $UpdateSource_Path = $EDMAuto_Path+"\"+$SS_UpdateSource_Folder
#$srcFile = $NAS_COPY_FROM+"EDMAuto\*.*"
#$DestLocation = $EDMAuto_Path
#Let's check all the possible paths that need to exist...
If(!(Test-Path "$EDMAuto_Path\Logs")){New-Item -type directory -Path "$EDMAuto_Path\Logs" | Out-Null}
If(!(Test-Path "$EDMAuto_Path\Scripts"))
{
New-Item -type directory -Path "$EDMAuto_Path\Scripts" | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\Scripts\*.*"
$objFolder = $objShell.NameSpace("$EDMAuto_Path\Scripts")
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
Else
{
Remove-Item -Path "$EDMAuto_Path\Scripts\*.*" -Force -Recurse
#Let's get everything there everytime this runs - we need to be sure everything in here is up to date.
$srcFile = $NAS_COPY_FROM+"EDMAuto\Scripts\*.*"
$objFolder = $objShell.NameSpace("$EDMAuto_Path\Scripts")
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
If(!(Test-Path $SetupEXE))
{
If (Test-Path $InstallMedia_Path){Remove-Item -Path $InstallMedia_Path -Force -Recurse}
New-Item -type directory -Path $InstallMedia_Path | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\$SS_Setup_Folder\*.*"
$objFolder = $objShell.NameSpace($InstallMedia_Path)
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
# if we made it to this point, then we successfully copied the stuff that we care about...
If (Test-Path $CntrlLogPath){$MessageStamp | Out-File $MediaLogFile}
}
If(!(Test-Path $UpdateSource_Path))
{
New-Item -type directory -Path $UpdateSource_Path | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\$SS_UpdateSource_Folder\*.*"
$objFolder = $objShell.NameSpace($UpdateSource_Path)
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
}
Function GetPrevInst
{
<#
This function checks to see if there is existing SQL Server instances on this host. If so - it warns the installer of the installed instance names so
they do not choose an instance name already installed. Also, it will check to see if there is a default instance, if so, the program will not
allow the choice to install a default instance.
#>
#This path exists no matter what version of sql server is installed - check it. If it's there, we need to check
#values.... We'll present them to the console.
If (Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")
{
$ValueNames = (Get-Item -Path "hklm:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL").getvaluenames()
If ($ValueNames)
{
ForEach ($ValueName in $ValueNames)
{
#Create a comma delimited variable to break up into an array.
If (!$instancenames)
{
$instancenames = $ValueName
}
Else
{
$instancenames += ","+$ValueName
}
}
}
}
If ($instancenames){$instancenames}
}
Function IntroForm
{
<#
This is the initial form to detect if the install of SQL Server will be
a named or default install.
#>
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $Form_Name
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
#$objForm.Size = New-Object System.Drawing.Size(400,220)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(125,100)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click({$script:x=$objListBox.SelectedItem.ToString();$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(220,100)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$Options = @("DEFAULT","NAMED")
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Point(10,50)
$objListBox.Size = New-Object System.Drawing.Size(100,40)
$objListBox.tabindex = 0
foreach($option in $Options)
{
$objListBox.Items.add($option) | Out-Null
}
$objListBox.SetSelected(0,$true)
$objForm.Controls.Add($objListBox)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(380,20)
$objLabel.Text = "Are you installing a `"Named`" or `"Default`" instance of SQL Server 2012?"
$objForm.Controls.Add($objLabel)
#$objTextBox = New-Object System.Windows.Forms.TextBox
#$objTextBox.Multiline = $true
#$objTextBox.Location = New-Object System.Drawing.Size(10,40)
#$objTextBox.Size = New-Object System.Drawing.Size(260,200)
#$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#if named instance is seleced, we'll set the value to true
#if $x isn't set, then they must have pressed the X button on the form.
if (!$x){exit}
if ($x -eq "NAMED"){$true}else{$false}
if ($Exit){exit}
}
Function MainForm ($Named)
{
<#
Now that we know if this is a named or default install, we'll gather the rest of the info.
1.) Named or Default instance
2.) SQL Server Service Account Name
3.) SQL Server Service Account Password
4.) SQL Agent Service Account Name
5.) SQL Agent Service Account Password
6.) Integrated Services Service Account Name
7.) Integrated Service Service Account Password
8.) SQL Server Full Text Account Name
9.) SQL Server Full Text Account Password
10.) DBA Privileged Group:
o PRV_EDM_DA_SRV_COMMBKGADMINS
o PRV_EDM_DA_SRV_CTFHDBADMINS
o PRV_EDM_DA_SRV_DANDBADMINS
o PRV_EDM_DA_SRV_TISOPSDBADMINS
o PRV_EDM_DA_SRV_WFADBADMINS
o PRV_EDM_DA_SRV_LENDINGDBADMINS
o PRV_EDM_DA_SRV_WFISDBAdmins
11.) SA Password
#>
#CREATE THE FORM:
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $Form_Name
#$objForm.Size = New-Object System.Drawing.Size(400,600)
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$ToolTip = New-Object System.Windows.Forms.ToolTip
$ToolTip.BackColor = [System.Drawing.Color]::LightGoldenrodYellow
$ToolTip.IsBalloon = $true
$ToolTip.InitialDelay = 150
$ToolTip.ReshowDelay = 150
########################################
#QUESTION 1 - Named Instance or Default
########################################
#CREATE THE LABEL
$objLbl_1 = New-Object System.Windows.Forms.Label
$objLbl_1.Location = New-Object System.Drawing.Size(0,10)
$objLbl_1.Autosize = $true
#SET the (X,Y) Y coordinate of location to a variable... Starting it at LINE 30...
$y = 10
If ($Named)
{
If ($default)
{
$Text = "A DEFAULT INSTANCE ALREADY EXISTS.`n"
}
Else
{
$Text = "You have selected to run a NAMED INSTANCE install.`n"
}
#lets add on to the $text - if there are existing instance names, let's let the installer know they can't use these names for this install:
If ($instanceArray)
{
Foreach($Instance in $instanceArray)
{
if ($Instance -ne "MSSQLSERVER")
{
If (!$textAdd)
{
$textAdd = "`nExisting Named Instances Detected! Do not use the following instance names for your install:`n`n$Instance"
$y+=30
}
Else
{
$textAdd += "`n$Instance"
$y+=10
}
}
}
$Text+=$textAdd
}
$Text+="`n`nInstance Name:"
$y+=38
}
Else
{
$Text = "You have selected to run a DEFAULT INSTANCE install."
$y+=10
}
$objLbl_1.Text = $Text
$objForm.Controls.Add($objLbl_1)
#LINE = This Label ends on line 50
#If named instance, add the text box to capture named instance
#SET THE "TAB ORDER OF THE CURSOR" Increment this var one after each control
$tabindex = 0
#CREATE THE TEXT BOX
If ($Named)
{
$y+=50
$objTextBox_Named = New-Object System.Windows.Forms.TextBox
$objTextBox_Named.Location = New-Object System.Drawing.Size(10,$y)
$objTextBox_Named.Size = New-Object System.Drawing.Size(250,10)
#Setting MAX Length of instance name to 16 - this is the most it can handle.
$objTextBox_Named.MaxLength = 16
$objTextBox_Named.tabindex = $tabindex
$objForm.Controls.Add($objTextBox_Named)
$tabindex++
$Named_Tip_Msg = "The instance name must be 16 characters or less, `nstart with a letter, not have any spaces or special `ncharacters and not use certain reserved words."
$ToolTip.SetToolTip($objTextBox_Named, $Named_Tip_Msg)
}
#LINE = This text box is on line 60
########################################
#QUESTION 2 - SQL Server Service Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_2 = New-Object System.Windows.Forms.Label
$objLbl_2.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_2.Autosize = $true
$objLbl_2.Text = "SQL Server SERVICE Account Name:"
$objForm.Controls.Add($objLbl_2)
#LINE 90
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SvcAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_SvcAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SvcAcctName.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SvcAcctName.Text = "AD-ENT\"
$objTxtBx_SvcAcctName.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SvcAcctName)
$tabindex++
$AcctName_Tip_Msg = "This is a domain account which is a member of the Windows `ngroup associated with the SQL GPO applied to the server."
$ToolTip.SetToolTip($objTxtBx_SvcAcctName, $AcctName_Tip_Msg)
#LINE 110
########################################
#QUESTION 3 - SQL Server Service Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_3 = New-Object System.Windows.Forms.Label
$objLbl_3.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_3.Autosize = $true
$objLbl_3.Text = "SQL Server SERVICE Account Password:"
$objForm.Controls.Add($objLbl_3)
#LINE 140
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SvcAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SvcAcctPW.PasswordChar = "*"
$objTxtBx_SvcAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SvcAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SvcAcctPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SvcAcctPW)
$tabindex++
$PW_Tip_Msg = "This is the password which was prepared before starting the installation.`n"`
+"The default password for domain accounts must be changed. The new password `n"`
+"must follow WF password construction rules."
$ToolTip.SetToolTip($objTxtBx_SvcAcctPW, $PW_Tip_Msg)
#LINE 160
########################################
#QUESTION 4 - SQL Server Agent Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_4 = New-Object System.Windows.Forms.Label
$objLbl_4.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_4.Autosize = $true
$objLbl_4.Text = "SQL Server AGENT Account Name:"
$objForm.Controls.Add($objLbl_4)
#LINE 180
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_AgtAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_AgtAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_AgtAcctName.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_AgtAcctName.Text = "AD-ENT\"
$objTxtBx_AgtAcctName.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_AgtAcctName)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_AgtAcctName, $AcctName_Tip_Msg)
#LINE 200
########################################
#QUESTION 5 - SQL Server Agent Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_5 = New-Object System.Windows.Forms.Label
$objLbl_5.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_5.Autosize = $true
$objLbl_5.Text = "SQL Server AGENT Account Password:"
$objForm.Controls.Add($objLbl_5)
#LINE 230
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_AgtAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_AgtAcctPW.PasswordChar = "*"
$objTxtBx_AgtAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_AgtAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_AgtAcctPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_AgtAcctPW)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_AgtAcctPW, $PW_Tip_Msg)
#LINE 250
########################################
#QUESTION 5.1 - Install SSIS?
########################################
#CREATE THE LABEL
$y+=30
$objLbl_ssis = New-Object System.Windows.Forms.Label
$objLbl_ssis.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_ssis.Autosize = $true
$objLbl_ssis.Text = "Check this box if you want to Install SSIS:"
$objForm.Controls.Add($objLbl_ssis)
#CREATE THE CHECK BOX
$y+=20
$objChkBx_SSISInstall = New-Object System.Windows.Forms.CheckBox
$objChkBx_SSISInstall.Location = New-Object System.Drawing.Size(10,$y)
$objChkBx_SSISInstall.Size = New-Object System.Drawing.Size(250,10)
$objChkBx_SSISInstall.tabindex = $tabindex
#$objTxtBx_SSISAcctName.ReadOnly = $false
$objChkBx_SSISInstall.Add_Click(
{
If ($objChkBx_SSISInstall.Checked)
{
$objTxtBx_SSISAcctName.ReadOnly = $false; $objTxtBx_SSISAcctName.Text = "AD-ENT\"; $objTxtBx_SSISAcctPW.ReadOnly = $false
}
Else
{
$objTxtBx_SSISAcctName.ReadOnly = $true; $objTxtBx_SSISAcctPW.ReadOnly = $true; $objTxtBx_SSISAcctName.Text = ""; $objTxtBx_SSISAcctPW.Text = ""
}
}
)
$objForm.Controls.Add($objChkBx_SSISInstall)
$tabindex++
$ToolTip.SetToolTip($objChkBx_SSISInstall, "SSIS is only needed if you are running or scheduling SSIS packages from this instance. `nMaintenance Plans will work without this component installed.")
#LINE 300
########################################
#QUESTION 6 - SSIS Service Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_6 = New-Object System.Windows.Forms.Label
$objLbl_6.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_6.Autosize = $true
$objLbl_6.Text = "SSIS Service Account Name:"
$objForm.Controls.Add($objLbl_6)
#LINE 280
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SSISAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_SSISAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SSISAcctName.Size = New-Object System.Drawing.Size(250,10)
#$objTxtBx_SSISAcctName.Text = "AD-ENT\"
$objTxtBx_SSISAcctName.tabindex = $tabindex
$objTxtBx_SSISAcctName.ReadOnly = $true
$objForm.Controls.Add($objTxtBx_SSISAcctName)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_SSISAcctName, $AcctName_Tip_Msg)
#LINE 300
########################################
#QUESTION 7 - SSIS Service Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_7 = New-Object System.Windows.Forms.Label
$objLbl_7.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_7.Autosize = $true
$objLbl_7.Text = "SSIS Service Account Password:"
$objForm.Controls.Add($objLbl_7)
#LINE 330
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SSISAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SSISAcctPW.PasswordChar = "*"
$objTxtBx_SSISAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SSISAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SSISAcctPW.tabindex = $tabindex
$objTxtBx_SSISAcctPW.ReadOnly = $true
$objForm.Controls.Add($objTxtBx_SSISAcctPW)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_SSISAcctPW, $PW_Tip_Msg)
#LINE 350
###########################################
#QUESTION 8 - Alternative SA Account Selection:
###########################################
#CREATE THE LABEL
$y+=30
$objLbl_8 = New-Object System.Windows.Forms.Label
$objLbl_8.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_8.Autosize = $true
$objLbl_8.Text = "SA Replacement Account:"
$objForm.Controls.Add($objLbl_8)
#CREATE THE COMBO BOX
$y+=20
# $SA_Options
$objListBox_SaAccnt = New-Object System.Windows.Forms.Listbox
$objListBox_SaAccnt.Location = New-Object System.Drawing.Point(10,$y)
$objListBox_SaAccnt.Size = New-Object System.Drawing.Size(200,20)
$objListBox_SaAccnt.tabindex = $tabindex
$tabindex++
foreach($option in $SA_Options)
{
$objListBox_SaAccnt.Items.add($option) | Out-Null
}
#$objComboBox.SetSelected(0,$true)
$objListBox_SaAccnt.SelectedIndex = 0
$objForm.Controls.Add($objListBox_SaAccnt)
$SaAccnt_Tip_Msg = "This is the replacement for the SA account. `nThis account will be created during installation. `nThe SA account will be disabled during the installation."
$ToolTip.SetToolTip($objListBox_SaAccnt, $SaAccnt_Tip_Msg)
########################################
#QUESTION 9 - SA / Alternative SA Password
########################################
#CREATE THE LABEL
$y+=20
$objLbl_11 = New-Object System.Windows.Forms.Label
$objLbl_11.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_11.Autosize = $true
$objLbl_11.Text = "SA Replacement Account Password:"
$objForm.Controls.Add($objLbl_11)
#LINE 530
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SAPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SAPW.PasswordChar = "*"
$objTxtBx_SAPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SAPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SAPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SAPW)
$tabindex++
$SAPW_Tip_Msg = "Enter a password following WF password construction rules."
$ToolTip.SetToolTip($objTxtBx_SAPW, $SAPW_Tip_Msg)
#LINE 550
###########################################
#QUESTION 10 - DBA Privileged Group to add:
###########################################
<#
#CREATE THE LABEL
$y+=30
$objLbl_10 = New-Object System.Windows.Forms.Label
$objLbl_10.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_10.Autosize = $true
$objLbl_10.Text = "Select one or more privileged groups to be added to the SQL Server sysadmin server role:"
$objForm.Controls.Add($objLbl_10)
#LINE 480
#CREATE THE COMBO BOX
$y+=20
# $PREV_Options = `
# @(`
# "AD-ENT\PRV_EDM_DA_SRV_COMMBKGADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_CTFHDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_DANDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_TISOPSDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_WFADBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_LENDINGDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_WFISDBAdmins"`
# )
$objListBox_PrivGrp = New-Object System.Windows.Forms.Listbox
$objListBox_PrivGrp.Location = New-Object System.Drawing.Point(10,$y)
$objListBox_PrivGrp.Size = New-Object System.Drawing.Size(300,100)
$objListBox_PrivGrp.SelectionMode = "MultiExtended"
$objListBox_PrivGrp.tabindex = $tabindex
$tabindex++
foreach($option in $PREV_Options)
{
$objListBox_PrivGrp.Items.add($option) | Out-Null
}
#$objComboBox.SetSelected(0,$true)
$objListBox_PrivGrp.SelectedIndex = 0
$objForm.Controls.Add($objListBox_PrivGrp)
$PrivGrp_Tip_Msg = "Hold down the CTRL or SHIFT keys to select multiple groups."
$ToolTip.SetToolTip($objListBox_PrivGrp, $PrivGrp_Tip_Msg)
#>
#LINE 500
#####################################
#OK BUTTON - LINE 600
#####################################
$y+=40 #100
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(145,$y)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = $tabindex
$OKButton.Add_Click({$script:Config_INI = Compile_INI})
$objForm.Controls.Add($OKButton)
$tabindex++
#######################################
#CANCEL BUTTON - LINE 600
######################################
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(240,$y)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = $tabindex
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
if ($Exit){exit}
return $Config_INI
}
Function Compile_INI
{
<#
This funciton will not only compile the configuration file, but before that, it does a few checks to ensure the
properties we are passing it will work for the install. If they don't pass, we will send the installer back to the
main form.
We are going to set a main bit to be used to ensure the set of checks are used... If the user "x"s out of the main form
after the checks run, the next validation window pops - we don't want that to happen.
#>
Set-Variable -name VALIDATION_CHECK -Value $true -Scope Script
If ($objTextBox_Named)
{
Set-Variable -Name InstanceName -Value $objTextBox_Named.text -Scope Script
}
Else
{
Set-Variable -Name InstanceName -Value "MSSQLSERVER" -Scope Script
}
If ($objChkBx_SSISInstall.Checked)
{
Set-Variable -Name SSIS_INSTALL -Value $true -Scope Script
}
#Let's double check that they aren't using an instance name that already exists on this system....
Foreach($Instance in $instanceArray)
{
if ($Instance -eq $InstanceName)
{
#Something didn't get populated - pop a message.
[Windows.Forms.MessageBox]::Show("$InstanceName - THIS INSTANCE NAME IS ALREADY IN USE ON THIS SYSTEM!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
}
<#
Let's now check to ensure the instance name abides by the Microsoft Naming Convention for Instance Names.
* The first character in the instance name must be a letter.
* Embedded spaces or other special characters are not allowed in instance names.
The backslash (\), comma (,), colon (:), semi-colon (;), single quote ('),
ampersand (&), and at sign (@) are also not allowed.
#>
If ($InstanceName)
{
If ($instancename.Substring(0,1) -match "[0-9]")
{
[Windows.Forms.MessageBox]::Show("$InstanceName - THE FIRST CHARACTER IN THE INSTANCE NAME CANNOT BE A NUMBER!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
$SpecChars = @('!','"','£','$','%','&','^','`*','(',')','@','=','+','¬','`','\','<','>','.','`?','/',':',';','#','~',"'",' ','-')
ForEach ($SpecChar in $SpecChars)
{
If ($instancename -like '*'+$SpecChar+'*'){$SpecCharFound=$true}
}
If ($SpecCharFound)
{
[Windows.Forms.MessageBox]::Show("$InstanceName - A SPECIAL CHARACTER WAS DETECTED IN THE INSTANCE NAME - THEY ARE NOT ALLOWED!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
}
#get all selected items in list box
<#
If ($objListBox_PrivGrp.SelectedItem)
{
ForEach ($PrivGrp in $objListBox_PrivGrp.SelectedItems)
{
If (!$PrivGrps)
{
$PrivGrps = "`""+$PrivGrp+"`""
}
Else
{
$PrivGrps += " `""+$PrivGrp+"`""
}
}
}
#>
$PrivGrps ='"PRV_EDM_FA_SRV_SQLServiceAccounts" "PRV_EDM_DA_SRV_WFISDBAdmins" '
switch ($LOBInstall){
DVE {$PrivGrps +='"PRV_EDM_DA_SRV_COMMBKGDBAdmins" "PRV_EDM_DA_SRV_CTFHDBADMINS" "PRV_EDM_DA_SRV_DANDBADMINS" "PRV_EDM_DA_SRV_WFADBADMINS" "PRV_EDM_DA_SRV_LENDINGDBADMINS"'; break}
CorpTech {$PrivGrps +='"PRV_EDM_DA_SRV_CTFHDBADMINS"'; break}
CommBank {$PrivGrps +='"PRV_EDM_DA_SRV_COMMBKGDBAdmins"'; break}
Lending {$PrivGrps +='"PRV_EDM_DA_SRV_LENDINGDBADMINS"'; break}
WIM {$PrivGrps +='"PRV_EDM_DA_SRV_WFADBADMINS"'; break}
default {$PrivGrps += ""; break}
}
if($EnvInstall -eq "PROD" -and $AD_Domain -eq 'AD-ENT')
{
switch ($LOBInstall){
DVE {$PrivGrps +=' "PRV_EDM_FA_SRV_DVE_SA_PRD"'; break}
CorpTech {$PrivGrps +=' "PRV_EDM_FA_SRV_CorpTech_SA_PRD"'; break}
CommBank {$PrivGrps +=' "PRV_EDM_FA_SRV_CommBank_SA_PRD"'; break}
Lending {$PrivGrps +=' "PRV_EDM_FA_SRV_Lending_SA_PRD"'; break}
WIM {$PrivGrps +=' "PRV_EDM_FA_SRV_WIM_SA_PRD"'; break}
default {$PrivGrps += ""; break}
}
}
elseif($EnvInstall -eq "NON-PROD" -and $AD_Domain -eq 'AD-ENT')
{
switch ($LOBInstall){
DVE {$PrivGrps +=' "PRV_EDM_FA_SRV_DVE_SA_NONPRD"'; break}
CorpTech {$PrivGrps +=' "PRV_EDM_FA_SRV_CorpTech_SA_NP"'; break}
CommBank {$PrivGrps +=' "PRV_EDM_FA_SRV_CommBank_SA_NP"'; break}
Lending {$PrivGrps +=' "PRV_EDM_FA_SRV_Lending_SA_NP"'; break}
WIM {$PrivGrps +=' "PRV_EDM_FA_SRV_WIM_SA_NP"'; break}
default {$PrivGrps += ""; break}
}
}
#make sure everything is populated - if not, pop a message saying they have to fill it out...
If (
($InstanceName -eq '')-or
($objTxtBx_SvcAcctName.text -eq '') -or
($objTxtBx_SvcAcctPW.text -eq '') -or
($objTxtBx_AgtAcctPW.text -eq '') -or
($objTxtBx_AgtAcctName.text -eq '') -or
($SSIS_INSTALL -and
(($objTxtBx_SSISAcctPW.text -eq '') -or
($objTxtBx_SSISAcctName.text -eq ''))) -or
(!$PrivGrps) -or
($objTxtBx_SAPW.text -eq '')
)
{
#Something didn't get populated - pop a message.
[Windows.Forms.MessageBox]::Show("All Fields Must Be Populated. Check install form.", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
ELSE
{
#SEtting the variable scope to the script level so we can comem back to this and show the installer what was used.
Set-Variable -Name SrvAcctName -Value $objTxtBx_SvcAcctName.text -Scope Script
Set-Variable -Name SvcAcctPW -Value $objTxtBx_SvcAcctPW.text -Scope Script
Set-Variable -Name AgtAcctName -Value $objTxtBx_AgtAcctName.text -Scope Script
Set-Variable -Name AgtAcctPW -Value $objTxtBx_AgtAcctPW.text -Scope Script
If ($SSIS_INSTALL)
{
Set-Variable -Name SSISAcctPW -Value $objTxtBx_SSISAcctPW.text -Scope Script
Set-Variable -Name SSISAcctName -Value $objTxtBx_SSISAcctName.text -Scope Script
}
Else
{
Set-Variable -Name SSISAcctPW -Value "N/A - WILL NOT INSTALL SSIS" -Scope Script
Set-Variable -Name SSISAcctName -Value "N/A - WILL NOT INSTALL SSIS" -Scope Script
}
Set-Variable -Name SA_AltName -Value $objListBox_SaAccnt.SelectedItem -Scope Script
#Set-Variable -Name FTAcctPW -Value $objTxtBx_FTAcctPW.text -Scope Script
#Use this line if we ONLY want to use what is select.
#it now uses a value they can type in... - override the options....
#Set-Variable -Name PrivGrp -Value $objComboBox_PrivGrp.SelectedItem.ToString() -Scope Script
Set-Variable -Name PrivGroups -Value $PrivGrps -Scope Script
Set-Variable -Name SAPW -Value $objTxtBx_SAPW.text -Scope Script
}
#Let's check to see if *-ENT\* is part of the account names - these have to be domain accounts.
If (
$SrvAcctName -notlike "*-ENT\*" -or
$AgtAcctName -notlike "*-ENT\*" -or
($SSIS_INSTALL -and
$SSISAcctName -notlike "*-ENT\*")
)
{
[Windows.Forms.MessageBox]::Show("All Service Accounts Must Be Domain Accounts.", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
#Now that we know they are domain accounts - let's make sure the login and passowrds are valid.
$SrvAccntCHK = Test-ADCredentials -username $SrvAcctName -password $SvcAcctPW -domain ($SrvAcctName.split("\"))[0] -AccntType "SERVICE ACCT"
$AgtAcctCHK = Test-ADCredentials -username $AgtAcctName -password $AgtAcctPW -domain ($AgtAcctName.split("\"))[0] -AccntType "AGENT ACCT"
If ($SSIS_INSTALL)
{
$SSISAccCHK = Test-ADCredentials -username $SSISAcctName -password $SSISAcctPW -domain ($SSISAcctName.split("\"))[0] -AccntType "SSIS ACCT"
}
$AcctChkMessage = ""
If ((!$SSIS_INSTALL)-and
($SrvAccntCHK.IsValid -eq "False" -or
$AgtAcctCHK.IsValid -eq "False")
)
{
$AcctChkMessage = "ACCOUNT VALIDATION CHECK FAILED! VERIFY LOGINS AND PASSWORDS ARE CORRECT!`n"`
+$SrvAccntCHK.AccntType+"`t"+$SrvAccntCHK.username+"`tIsValid = "+$SrvAccntCHK.IsValid+"`n"`
+$AgtAcctCHK.AccntType+"`t"+$AgtAcctCHK.username+"`tIsValid = "+$AgtAcctCHK.IsValid+"`n"
}
If (($SSIS_INSTALL) -and
($SSISAccCHK.IsValid -eq "False" -or
$SrvAccntCHK.IsValid -eq "False" -or
$AgtAcctCHK.IsValid -eq "False"))
{
$AcctChkMessage = "ACCOUNT VALIDATION CHECK FAILED! VERIFY LOGINS AND PASSWORDS ARE CORRECT!`n"`
+$SrvAccntCHK.AccntType+"`t"+$SrvAccntCHK.username+"`tIsValid = "+$SrvAccntCHK.IsValid+"`n"`
+$AgtAcctCHK.AccntType+"`t"+$AgtAcctCHK.username+"`tIsValid = "+$AgtAcctCHK.IsValid+"`n"`
+$SSISAccCHK.AccntType+"`t"+$SSISAccCHK.username+"`tIsValid = "+$SSISAccCHK.IsValid+"`n"
}
If($AcctChkMessage)
{
[Windows.Forms.MessageBox]::Show($AcctChkMessage, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
$script:INI_OUT = ";SQL Server 2012 Configuration File`r`n"+
"[OPTIONS]`r`n"+
"INSTANCENAME=`"$InstanceName`"`r`n"+
"INSTANCEID=`"$InstanceName`"`r`n"+
"SQLSVCACCOUNT=`"$SrvAcctName`"`r`n"+
"AGTSVCACCOUNT=`"$AgtAcctName`"`r`n"+
#"ISSVCACCOUNT=`"$SSISAcctName`"`r`n"+
"SQLSYSADMINACCOUNTS=$PrivGroups`r`n"+
"SQLSVCPASSWORD=`"$SvcAcctPW`"`r`n"+
"AGTSVCPASSWORD=`"$AgtAcctPW`"`r`n"+
#"ISSVCPASSWORD=`"$SSISAcctPW`"`r`n"+
"SAPWD=`"$SAPW`"`r`n"+
"INSTANCEDIR=`"$InstallSqlPath`"`r`n"+
"INSTALLSQLDATADIR=`"$InstallDataPath`"`r`n"+
"INSTALLSHAREDDIR=`"$InstallSqlPath`"`r`n"+
"INSTALLSHAREDWOWDIR=`"$InstallWowPath`"`r`n"+
"UpdateSource=`"$UpdateSource_Path`"`r`n`r`n"+
"ACTION=`"Install`"`r`n"+
"IACCEPTSQLSERVERLICENSETERMS=`"True`"`r`n"+
"ENU=`"True`"`r`n"+
#"FEATURES=SQLEngine,Replication,CONN,IS,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"+
"X86=`"False`"`r`n"+
"ERRORREPORTING=`"False`"`r`n"+
"SQMREPORTING=`"False`"`r`n"+
"UpdateEnabled=`"True`"`r`n"+
"SQLSVCSTARTUPTYPE=`"Automatic`"`r`n"+
"AGTSVCSTARTUPTYPE=`"Automatic`"`r`n"+
#"ISSVCSTARTUPTYPE=`"Automatic`"`r`n"+
#"BROWSERSVCSTARTUPTYPE=`"Disabled`"`r`n"+
"TCPENABLED=`"1`"`r`n"+
"NPENABLED=`"1`"`r`n"+
"SQLCOLLATION=`"SQL_Latin1_General_CP1_CI_AS`"`r`n"+
"SECURITYMODE=`"SQL`"`r`n"
#We only need the browser service if it's a named instance....
If ($InstanceName -ne "MSSQLSERVER")
{
$script:INI_OUT += "BROWSERSVCSTARTUPTYPE=`"Automatic`"`r`n"
}
Else
{
$script:INI_OUT += "BROWSERSVCSTARTUPTYPE=`"Disabled`"`r`n"
}
If ($SSIS_INSTALL)
{
$script:INI_OUT += "FEATURES=SQLEngine,Replication,CONN,IS,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"+
"ISSVCACCOUNT=`"$SSISAcctName`"`r`n"+
"ISSVCPASSWORD=`"$SSISAcctPW`"`r`n"+
"ISSVCSTARTUPTYPE=`"Automatic`"`r`n"
}
Else
{
$script:INI_OUT += "FEATURES=SQLEngine,Replication,CONN,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"
}
#Close the main form
$objForm.Close()
Return $script:INI_OUT
}
##commenting out this block of code, could be used later... I'm leaving it in cause it did work to launch the setup this way.
#Function JobKickOff
#{
# #I've set the folder path of the setup.exe folder to a variable, along with the config file path.
# #this was done in the event we want to allow other locations for execution.
#
# $SetupFolder = $SQLAdmin_Path+$SS_Setup_Folder
# $ScriptBlock = {param($SetupFolder_, $ConfigFile_) cd $SetupFolder_;.\setup.exe /configurationfile=$ConfigFile_ /q `
# /IACCEPTSQLSERVERLICENSETERMS}
#
#
#
# Start-Job -name SS2K12_Install -ScriptBlock $ScriptBlock -Arg $SetupFolder, $ConfigFile | Out-Null
#
#}
#
#Function Col-Jobs
#<#Function Col-Jobs
# This function will monitor the sql install and flash a message to the powershell console. If the install doesn't finish within one hour
# The script will stop monitoring the install and exit the powershell script - a message will flash to the console stating this.
##>
#{
# #any error lurking around, clear them.. we have to test this in this function
# $Error.Clear()
#
# $i = 0
# $messageout = $now + "SQL Install Running"
# Write-Host $messageout
# Do
# {
# $CompleteJobs = get-job | where {$_.State -ne "Running"}
#
#
# If ($CompleteJobs)
# {
# ForEach ($compJob in $CompleteJobs)
# {
# $output += Receive-Job $compJob.id
# #any errors that may have came from this:
# $output += $Error
# Remove-Job $compJob.id
# }
# clear
# $time = Get-Date | Out-String
# If ($Error)
# {
# $messageout += "`n`n"+ $time + "!!!!!SQL Install Completed With Errors`n`n"
# }
# Else
# {
# $messageout += "`n`n"+ $time + " SQL Install Complete"
# }
# Write-Host $messageout
# }
#
# $Anyjobs = Get-Job
#
# If ($Anyjobs)
# {
# Start-Sleep -Seconds 10
# $messageout += "."
# Clear
# Write-Host $messageout
# }
#
# ++$i
# $Anyjobs = Get-Job
# }
# Until
# (
# (!$Anyjobs) -or ($i -eq 3600) #giving the install 1 hour....
# )
#
# If (!$output)
# {
# clear
# $time = Get-Date | Out-String
# $messageout += "`n`n" + $time + " SQL Install running over 1 hour - Poweshell Script Ending. - Setup.exe will continue to run..."
# Write-Host $messageout
# $output = "!!!!!!!!!!!SQL INSTALL STILL RUNNING!!!!!!!!!!!"
# }
#
# $output
#}
Function ConfirmInstall
{
$objFormConf = New-Object System.Windows.Forms.Form
$objFormConf.Text = $Form_Name
$objFormConf.Autosize = $true
$objFormConf.AutosizeMode = "GrowAndShrink"
$objFormConf.AutoScroll = $true
#$objForm.Size = New-Object System.Drawing.Size(400,220)
$objFormConf.StartPosition = "CenterScreen"
$objFormConf.KeyPreview = $True
$objFormConf.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objFormConf.Close()}})
$ConfMsg0 = "If this information is correct, you are now ready to install."
$ConfMsg1 = "LOB:`n"+
"Environment:`n"+
"Instance Name:`n"+
"Service Acct Name:`n"+
"Service Acct PW:`n"+
"Agent Acct Name:`n"+
"Agent Acct PW:`n"+
#"SSIS Acct Name:`n"+
#"SSIS Acct PW:`n"+
"SA Alt Acct Name:`n"+
"SA PW:`n"
#"Privledged Group(s)"
If ($SSIS_INSTALL)
{
$ConfMsg1 += "SSIS Acct Name:`n"+
"SSIS Acct PW:`n"+
"Privledged Group(s)`n"+
"added to SysAdmin`n"+
"role:"
}
Else
{
$ConfMsg1 += "Privledged Group(s)`n"+
"added to SysAdmin`n"+
"role:"
}
$ConfMsg2 = "$LOBInstall`n"+
"$EnvInstall`n"+
"$InstanceName`n"+
"$SrvAcctName`n"+
"*****`n"+
"$AgtAcctName`n"+
"*****`n"+
#"$SSISAcctName`n"+
#"*****`n"+
"$SA_AltName`n"+
"*****`n"
#$PrivGroups.Replace(" ","`n") +"`n"
If ($SSIS_INSTALL)
{
$ConfMsg2 += "$SSISAcctName`n"+
"*****`n"+
$PrivGroups.Replace(" ","`n") +"`n"
}
Else
{
$ConfMsg2 += $PrivGroups.Replace(" ","`n") +"`n"
}
#Get the line count of number of groups...
$count = 0
ForEach ($group in $PrivGroups.Split(" ")){$count+=10}
#LINE COUNT = 180 $count = number of groups - add that to 180. That's where we put the next line.
$linecount = (220 + $count) #(180 + $count)
$ConfMsg3 = "Click `"Install`" to install SQL Server with the provided information."
$objLbl0_conf = New-Object System.Windows.Forms.Label
$objLbl0_conf.Location = New-Object System.Drawing.Size(10,20)
$objLbl0_conf.Autosize = $true
$objLbl0_conf.Text = $ConfMsg0
$objFormConf.Controls.Add($objLbl0_conf)
$objLbl1_conf = New-Object System.Windows.Forms.Label
$objLbl1_conf.Location = New-Object System.Drawing.Size(10,40)
$objLbl1_conf.Autosize = $true
$objLbl1_conf.Text = $ConfMsg1
$objFormConf.Controls.Add($objLbl1_conf)
$objLbl2_conf = New-Object System.Windows.Forms.Label
$objLbl2_conf.Location = New-Object System.Drawing.Size(130,40)
$objLbl2_conf.Autosize = $true
$objLbl2_conf.Text = $ConfMsg2
$objFormConf.Controls.Add($objLbl2_conf)
$objLbl3_conf = New-Object System.Windows.Forms.Label
$objLbl3_conf.Location = New-Object System.Drawing.Size(10,$linecount)
$objLbl3_conf.Autosize = $true
$objLbl3_conf.Text = $ConfMsg3
$objFormConf.Controls.Add($objLbl3_conf)
$linecount += 40
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,$linecount)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "INSTALL"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click({$script:x2=$true;$objFormConf.Close()})
$objFormConf.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,$linecount)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "CANCEL"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objFormConf.Close();$Exit=$true})
$objFormConf.Controls.Add($CancelButton)
$objFormConf.Topmost = $True
$objFormConf.Add_Shown({$objFormConf.Activate()})
[void] $objFormConf.ShowDialog()
#if these conditions are met, then we're killing it.
If ($Exit -or !($script:x2))
{
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tConfirmation Form - Canceled - Exiting Script.`r`n")
exit
}
Else
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tConfirmation Form - Accepted`r`n")
}
}
Function SetPort
{
$BasePath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server"
If (Test-Path $BasePath)
{
#get all the installed instances
$SubKeys = (Get-Item -Path $BasePath).getsubkeynames()
ForEach ($SubKey in $SubKeys)
{
#roll through all the instances and see what ports they are using - EXCEPT the newly installed instance...
If ($SubKey -like "MSSQL*.*" -and $SubKey -notlike "MSSQL*.$InstanceName")
{
$PortItems = Get-ItemProperty -Path "$BasePath\$SubKey\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
$TcpDynPort = $PortItems.TcpDynamicPorts
$TcpStatPort = $PortItems.TcpPort
If ($TcpStatPort)
{
If(!$UsedPorts){$UsedPorts = $TcpStatPort}
Else {$UsedPorts += ","+$TcpStatPort}
}
If ($TcpDynPort)
{
If(!$UsedPorts){$UsedPorts = $TcpDynPort}
Else {$UsedPorts += ","+$TcpDynPort}
}
}
#While we're here, let's get the base key for the newly instance - we need to use it later
ElseIf($SubKey -like "MSSQL*.$instancename")
{
$BaseKey_installed_path = "$BasePath\$SubKey\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
}
}
If ($UsedPorts)
{
ForEach ($UsedPort in $UsedPorts.Split(","))
{
If($UsedPort -gt 11000 -and $UsedPort -lt 11999)
{
if(!$HighestUsedPort)
{
$HighestUsedPort = $UsedPort
}
Elseif($HighestUsedPort -lt $UsedPort)
{
$HighestUsedPort = $UsedPort
}
}
}
}
If (!$HighestUsedPort){$HighestUsedPort=11000}
$NextAvailPort = [int]$HighestUsedPort+1
#We now know what port is free to use, let's set the newly installed SQL Server to that port
Set-ItemProperty -Path $BaseKey_installed_path -Name TcpDynamicPorts -Value ''
Set-ItemProperty -Path $BaseKey_installed_path -Name TcpPort -Value $NextAvailPort
#Let's return this as an output - we're going to need this for setting the firewall...
$NextAvailPort
}
}
Function RestartSQLServices
{
#Let's get the service objects set for the installed instance
$AgentService = get-service | where-object {$_.DisplayName -eq "SQL Server Agent ($InstanceName)" }
$SQLService = get-service | where-object {$_.DisplayName -eq "SQL Server ($InstanceName)" }
If ($AgentService.Status -eq 'Running')
{
"Stopping the "+$AgentService.DisplayName+" Service..." | Write-Host
#if it's running, let's stop it...
$AgentService.Stop()
#let's give it a few seconds.. then we'll check it's status again...
Start-Sleep -Seconds 3
$counter = 0
#looping 9 times - pausing 3 sec between loops.
While ($counter -lt 10)
{
$AgentService.Refresh()
If ($AgentService.Status -eq 'Stopped'){$counter = 100}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
If ($AgentService.Status -eq 'Stopped' -and $SQLService.Status -eq 'Running')
{
"The "+$AgentService.DisplayName+" Service is "+$AgentService.Status | Write-Host
"Stopping the "+$SQLService.DisplayName+" Service..." | Write-Host
#Ok - it's now time to stop the SQL Server Service...
$SQLService.Stop()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$SQLService.Refresh()
If ($SQLService.Status -eq 'Stopped'){$counter = 100}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
#Let's Restart SQL SErver Service
If ($SQLService.Status -eq 'Stopped')
{
"The "+$SQLService.DisplayName+" Service is "+$SQLService.Status | Write-Host
"Starting the "+$SQLService.DisplayName+" Service..." | Write-Host
$SQLService.Start()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$SQLService.Refresh()
If ($SQLService.Status -eq 'Running'){$counter = 100;$restart=$true}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
If ($AgentService.Status -eq 'Stopped' -and $SQLService.Status -eq 'Running')
{
"The "+$SQLService.DisplayName+" Service is "+$SQLService.Status | Write-Host
"Starting the "+$AgentService.DisplayName+" Service..." | Write-Host
#Ok - it's now time to stop the SQL Server Service...
$AgentService.Start()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$AgentService.Refresh()
If ($AgentService.Status -eq 'Running'){$counter = 100;"The "+$AgentService.DisplayName+" Service is "+$AgentService.Status | Write-Host}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
Return $restart
}
Function SQLServicePing
{
<#
In order to see if the newly installed sql server REALLY got installed,
because there is no good return code to analyze from the installer, we're going to
analyze the service. See if it's there, and running. If so, we can connect to it and
finish up our installation.
Things we've already attemptted - a SQL Ping doesn't work efficiently, and checking the registry will return
unpredictable results due to how soon the registry is refreshed with the newly added information to this scripts shell.
this function returns true if new instance is running, and false if not found, or not running.
#>
Try
{
$SQLService = get-service -ErrorAction SilentlyContinue | where-object {$_.DisplayName -eq "SQL Server ($InstanceName)" }
}
Catch [Exception]
{
#Service name not found - return false
Return $false
}
If ($SQLService)
{
If ($SQLService.status -eq "Running"){Return $true}Else{Return $false}
}
Else
{
Return $false
}
}
Function Test-ADCredentials
{
Param($username, $password, $domain, $AccntType)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain)
New-Object PSObject -Property @{
UserName = $username;
IsValid = $pc.ValidateCredentials($username, $password).ToString();
AccntType = $AccntType
}
}
Function Log-Message ([bool]$Write, [string]$Msg)
{
Set-Variable -Name LogMessage -value "$LogMessage$Msg" -Scope Script
#Send Message to console:
Write-Host $Msg
If ($Write)
{
If (Test-path $CntrlLogPath) {$LogMessage | Out-File -FilePath $InstallLogFile}
#Local Log Folder - may not exist due to how the program logic got to this point.
#test variables, and then test path - if all there, we'll have a local copy of the log as well.
If ($EDMAuto_Path)
{
$LocalLog_Path = $EDMAuto_Path+"\Logs\"
If (Test-Path $LocalLog_Path)
{
$localLogfile = $LocalLog_Path+$LogFilePrefix+"_Install_"+$datetimestamp+".txt"
#$localLogfile
$LogMessage | Out-File -FilePath $localLogfile
Write-Host "Log file of this install can be found: $localLogfile"
}
}
}
}
#################
# FUNCTIONS END
#################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#####################
# PROGRAM LOGIC BEGIN
#####################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#############
#STEP 0 BEGIN
#############
<#
It is vital this script is run as admin - if not we must send a message and kill the script. this will not work unless run as admin.
#>
$Admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")
If (!$Admin)
{
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tScript was runas NON Admin authority - Error - killing script.`r`n")
$message = "!!!ERROR!!!`n`n"+
"Install MUST be run as administrator.`n`n"+
"Run this with runas administrator."
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Error) | Out-Null
# We will only store a central log file for this one... if we can't get to it, we'll just flash this message on the
Exit
}
$Release = GetRelease
If (!($Release.IsSupported))
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! Release Level $($Release.Version).`r`n")
$message = "!!!WARNING - Release Version!!! $($Release.Version)`n`n"+
"Install has been fully tested on $MinSupportRelease or greater.`n`nContinue at your own risk..."
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name,[Windows.Forms.MessageBoxButtons]::OKCancel, [Windows.Forms.MessageBoxIcon]::Warning)
# We will only store a central log file for this one... if we can't get to it, we'll just flash this message on the
If ($OUTPUT-eq"Cancel" -or !$OUTPUT){Exit}
}
#Check to see if GPO is there...
$RSOP_GPO_SQL = Get-WmiObject -Namespace root\RSOP\Computer -Class RSOP_GPO | Where-Object {$_.name -like "CPS_CORP_SQL_2008_2012_2014"}
$RSOP_GPO_SQL_OR = Get-WmiObject -Namespace root\RSOP\Computer -Class RSOP_GPO | Where-Object {$_.name -like "CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide"}
If (!$RSOP_GPO_SQL)
{
$message = "!!!WARNING - GPO Check Failed. CPS_CORP_SQL_2008_2012_2014 Policy was not detected.`n`n"+
"This instance you are installing will not be following the EDM standard and may not function correctly without the CPS_CORP_SQL_2008_2012_2014 GPO applied.`n`nDo you want to CANCEL this installation?`n"
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::YesNo, [Windows.Forms.MessageBoxIcon]::Warning)
If ($OUTPUT-eq"Yes" -or !$OUTPUT){Exit}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! CPS_CORP_SQL_2008_2012_2014 Policy GPO was not detected. Installation continuing.`r`n")
}
If (!$RSOP_GPO_SQL_OR)
{
$message = "!!!WARNING - GPO Check Failed. CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide Policy was not detected.`n`n"+
"This instance you are installing will not be following the EDM standard and may not function correctly without the CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide GPO applied.`n`nDo you want to CANCEL this installation?`n"
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::YesNo, [Windows.Forms.MessageBoxIcon]::Warning)
If ($OUTPUT-eq"Yes" -or !$OUTPUT){Exit}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide Policy GPO was not detected. Installation continuing.`r`n")
}
#############
#STEP 0 END
#############
<#
#############
#STEP 1 BEGIN
#############
2 variables were set at the very top of this script - we need to ensure the paths exist, otherwise
everything collected will not work, and setup will not kick off.
#############
#>
#Let's check the paths... Default is D drive... If d doesn't exist, we'll check C
#Base Admin Path
#Set-Variable -Name SQLAdmin_Path -Value "D:\SQLAdmin\" -Scope Script
#install media location:
#Set-Variable -Name SS_Setup_Folder -Value "SQLServer2012EE\" -Scope Script
#config file path:
#Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#install media should be here - if it's not, they may not have copied it down...
##SQLADMIN Folder Admin Path (ROOT FOLDER)
#Set-Variable -Name SQLAdmin_Folder -Value "SQLAdmin" -Scope Script
#
##SQLADMIN Folder Admin Path
#Set-Variable -Name EDMAuto_Folder -Value "EDMAuto" -Scope Script
#
##install media location:
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script
#
##UpdateSource media location:
#Set-Variable -Name SS_UpdateSource_Folder -Value "Media\SQL2012UpdateSource" -Scope Script
If(GetLobEnvironment){
#We have to set the edition of sql server we want to install - has to be the first step.
If (GetEdition)
{
#The following function sets the binary and data drives for the install...
If (getDriveInfo)
{
$SQLAdmin_Path = $Install_Drive+"\"+$SQLAdmin_Folder
$EDMAuto_Path = $SQLAdmin_Path+"\"+$EDMAuto_Folder
$LocalLog_Path = $EDMAuto_Path+"\Logs"
$InstallMedia_Path = $EDMAuto_Path+"\"+$SS_Setup_Folder
$UpdateSource_Path = $EDMAuto_Path+"\"+$SS_UpdateSource_Folder
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe following paths will be used for the install:`r`n"`
+"`t`t`t$InstallMedia_Path`r`n`t`t`t$UpdateSource_Path`r`n")
#$SQLAdmin_Path
#$EDMAuto_Path
#$InstallMedia_Path
#$UpdateSource_Path
#"C:\Program Files\Microsoft SQL Server\110\Tools\Binn"
}
}
}
$SetupEXE = "$InstallMedia_Path\Setup.EXE"
If (!(Test-Path $SetupEXE))
{
$message = "SQL Server Install Media - COPY PROCESS.`n`n"+
"INSTALL MEDIA WILL BE COPIED DOWN - DO NOT CANCEL COPY PROCESSES!!`n"+
"Media will be copied to:`n"+$EDMAuto_Path
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tUnable to locate setup.exe - Begin Media Copy.`r`n")
#Execute the function to get the media copied local...
GetMedia
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tMedia copy complete.`r`n")
}
Else
{
#There are checks in here to validate certain directories have up to date info - but the main copy won't happen since
#it's been found in the check....
GetMedia
}
#############
#STEP 1 END
#############
<#
####################
STEP 2 BEGIN
##############################################################
Gather all the required information to run the SQL Server installation. This will produce
the $Config_INI variable that will be created and placed in the file:
D:\SQLAdmin\ConfigurationFile\ConfigurationFile.ini
##############################################################
#>
#IntroForm fuction is questioning if this is a named instance install. If it is, the value is set to $true and passed to
#the MainForm
#The MainForm function is run, and gather the rest of the information from the installer. When the installer "oks" the form,
#the information is passed into another function called: Compile_INI This function detects if any questions were left blank,
# and will then populate the variable $Config_INI.
#The bottem line is, Step one creates the $Config_INI, and passes along each config item as a varible.
#lets figure out if there are instances already installed first.
$instances = GetPrevInst
If ($instances)
{
$instanceArray=$instances.split(",")
#ok there are instances already installed - let's do a quick check to see if one of these
#instances = MSSQLSERVER - which means, a default instance has already been installed.
Foreach($Instance in $instanceArray)
{
if ($Instance -eq "MSSQLSERVER"){$default=$true}
}
}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tLaunching installation forms for required install data.`r`n")
#Let's call the intro form - if there is no default instance.
If ($default)
#if there is a default instance already installed - pass $true to Mainform, that tells it to ask for a Named instance install
{$Config_INI = MainForm ($default)}
Else
#if there is no default instance installed, then, let's ask the installer what they want to install, this decision will get passed to the main form.
{$Config_INI = MainForm (IntroForm)}
If (!$Config_INI)
{
Log-Message -Write $True -Msg ("$(Get-Date -format 'u')`tData Collection forms returned no data - Error - suspect installer killed the form. EXITING SCRIPT`r`n")
exit
}
########################
#STEP 2 END
########################
########################
#STEP 3 BEGIN
########################
<#
Here's our list of config variables we have at this point:
$InstanceName
$SrvAcctName
$SvcAcctPW
$AgtAcctName
$AgtAcctPW
$SSISAcctPW
$SSISAcctName
$FTAcctName
$FTAcctPW
$PrivGrp
$SAPW
$Config_INI -- the one we're going to use to create the ini file...
$SetupEXE -
#Base Admin Path
#Set-Variable -Name SQLAdmin_Path -Value "D:\SQLAdmin\" -Scope Script
#install media location:
#Set-Variable -Name SS_Setup_Folder -Value "SQLServer2012EE\" -Scope Script
#config file path:
#Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#>
#Let's create the config file -
#Create the folder if it doesn't exist:
$Config_Path = $SQLAdmin_Path+"\"+$Config_Folder
If (!(Test-Path $Config_Path))
{ $newfolder = $SQLAdmin_Path + "\" + $Config_Folder
# we already know the sqladmin folder exists, otherwise step one would have failed. so, just the config folder doesn't exist.
New-Item -Path $newfolder -ItemType directory | Out-Null
}
#If we're at this point, and the validation checks done in the configini function failed, we need to
#make sure they didn't just X out of the form after going back to the main form...
#it's a loophole found when passing between forms... if it's false, kill this script.. don't log a message.
If (!$VALIDATION_CHECK){Exit}
#We are ready to create the config file - but, before we do, let's just ask the installer if they are sure they want to continue with all the information we've gathered
#this function will decide if the script kills or not...
ConfirmInstall
$ConfigFile = $Config_Path+"ConfigurationFile.ini"
#Let's create the config file used for THIS install:
$Config_INI | Out-File -Filepath $ConfigFile -Force
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$ConfigFile CREATED...`r`n")
########################
#STEP 3 END
########################
########################
#STEP 4 BEGIN
########################
<#
If we're at step 4, that means we have our config file created and waiting to be used with a silent sql server install...
We're going to launch the install with a start-job commandlet. while it runs, the powershell script will go to sleep
and check it's progress until it completes. Once complete, we'll more on to step 5.
#>
#this job runs in the background... See function for more details...
$now = Get-Date | Out-String
#JobKickOff
$now
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t*BEGIN INSTALL OF INSTANCE: $InstanceName`r`n")
#$SetupFolder = $SQLAdmin_Path+$SS_Setup_Folder
#cd $InstallMedia_Path;.\setup.exe /configurationfile=$ConfigFile /INDICATEPROGRESS /q
cd $InstallMedia_Path;.\setup.exe /configurationfile=$ConfigFile /INDICATEPROGRESS /qs
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t***END INSTALL OF INSTANCE: $InstanceName`r`n")
#$ScriptBlock = {param($SetupFolder_, $ConfigFile_) cd $SetupFolder_;.\setup.exe /configurationfile=$ConfigFile_ /q `
# /INDICATEPROGRESS}
#$InstallStatus = Col-Jobs
########################
#STEP 4 END
########################
########################
#STEP 5 BEGIN
########################
#Clean Up - Remove Config file because it contains passwords
#$InstallStatus
#delete the config file
Remove-Item $ConfigFile -Force
Write-Host "$Configfile -- Has been REMOVED`n`n"
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$ConfigFile REMOVED...`r`n")
########################
#STEP 5 END
########################
########################
#STEP 6 BEGIN - POST INSTALL STEPS
########################
<#
IF there are no errors after the install, we're going to do the following post install items:
1.) Update the listening port to a port number between 11000 and 11999 - depending on what's already in use.
2.) Update the firewall to allow newly added port, ssis, and browser
The silent install passes a error code 0 even if it fails. To determine if the install worked, let's check
the registery for the new instance name. If it exists, then it work. If not, we'll throw an error.
We're going to use the function serverping to see if the instance exists...
#>
#SQLSERVER INSTANCE NAME TO CONNECT TO:
If ($instancename -eq "MSSQLSERVER")
{
Set-Variable -Name SQLInstance -Value $hostname -Scope Script
}
ELSE
{
Set-Variable -Name SQLInstance -Value "$hostname\$instancename" -Scope Script
}
If (!(SQLServicePing))
{
$Error
#An actual error may not have been detected - let's let the installer know that something happened because the actual instance doesn't exist.
$message = "!!!ERROR - NEW INSTANCE DOESN'T EXIST!!!`n`n"+
"Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tThe service for $InstanceName is not detected, or is not running. Either the installation errored or was stopped short of completion.`r`n"`
+ "`t`t`tCheck the bootstrap logs under C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log on $hostname`r`n`t`t`tEXITING SCRIPT.`r`n`r`n$Error")
Exit
}
Else
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe service for $InstanceName is detected. Begin Post Installation Processes...`r`n")
}
#If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instancename"))
#{
# #An actual error may not have been detected - let's let the installer know that something happened because the actual instance doesn't exist.
# $message = "!!!ERROR - NEW INSTANCE DOESN'T EXIST!!!`n`n"+
# "Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
# [Windows.Forms.MessageBox]::Show($message, `
# $Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
#
# Exit
#}
#Check the error status - if the install went without error, we'll continue on.
If (!$Error)
{
#We're going to check the port number and give it a NON dynamic port number > 11000
#Let's check all the port numbers of any SQL Instance. Make this newly installed instance 1 greater than the existing largest.
Write-Host "Install Success"
#lets do our first post install change - update the port this newly installed sql server is using.
$TCP_Port = SetPort
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tListening Port for $instancename has been updated to $TCP_Port.`r`n")
#FIREWALL UPDATE:
$newRuleName = "SQLServerEng_$instancename"
netsh advfirewall firewall add rule name = $newRuleName dir = in protocol = tcp action = allow localport = $TCP_Port remoteip = ANY profile = ANY
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tFireWall Rule added to allow anything to connect to Port $TCP_Port`r`n")
#if the port number is 11001, this means it's the first install of sql server for this program to install - set the next 2 only once...
If([int]$TCP_Port -eq 11001)
{
netsh advfirewall firewall add rule name = SQLServerSSIS dir = in protocol = tcp action = allow localport = 135 remoteip = ANY profile = ANY
netsh advfirewall firewall add rule name = SQLServerBrowser dir = in protocol = UDP action = allow localport = 1434 remoteip = ANY profile = ANY
}
#Let's restart the new instance - make sure the new port assignment takes effect.
If(RestartSQLServices){Write-Host "$instancename has been restarted - new port assignment complete."}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$instancename has been restarted - new port assignment complete.`r`n")
}
Else
{
#There was an error detected - let's let the installer know that, and also let them know the following information was not configured due to the error detected.
$message = "!!!INSTALL ERROR DETECTED!!!`n`n"+
"Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`t!!!ERROR DETECTED!!!`r`n"`
+ "`t`t`tCheck the bootstrap logs under C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log on $hostname`r`n`t`t`tEXITING SCRIPT - See Error Details Below...`r`n`r`n$Error")
Exit
}
########################
#STEP 6 END
########################
########################
#STEP 7 BEGIN
########################
#On a FRESH install of SQL SErver - sql server pathes are not yet known in the path, therefore we must give the entire path of the sqlcmd.exe executable.
#"$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe"
#in the command for sqlcmd.exe, we're doing a "cd" first....
#CREATE alternate sa account:
$SQL_AltSA_Create = "CREATE LOGIN ["+$SA_AltName+"] WITH PASSWORD=N'"+$SAPW+"', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON;`n" + `
"ALTER SERVER ROLE [sysadmin] ADD MEMBER ["+$SA_AltName+"];"
#DISABLE SA
$SQL_DisableSA = "ALTER LOGIN [sa] DISABLE;`n" + `
"select [name],case is_disabled when 1 then 'DISABLED' when 0 then 'ENABLED' END AccountStatus from master.sys.sql_logins where [name] in ('sa','"+$SA_AltName+"');"
##SQLSERVER INSTANCE NAME TO CONNECT TO:
#If ($instancename -eq "MSSQLSERVER")
#{
# $SQLInstance = $hostname
#}
#ELSE
#{
# $SQLInstance = "$hostname\$instancename"
#}
If (Test-Path -Path "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn")
{
#CONNECT AND CREATE
cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U sa -P $SAPW -Q "$SQL_AltSA_Create;"
If(!$error){Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe replacment SA account has been created.`r`n")}
#CONNECT AND DISABLE
cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U $SA_AltName -P $SAPW -Q "$SQL_DisableSA;"
If(!$error){Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe SA account has been Disabled.`r`n")}
#INSTALL EAM ACCESS OBJECTS - deploy_eam_allver.sql
#THIS SHOULD HAVE BEEN COPIED DURING THE MAIN COPY PROCESS: $EDMAuto_Path\Scripts\deploy_eam_allver.sql
####
# As of 08/16/2013 the EAM objects are no longer being included in the install package
####
#$EAM_DEPLOY_SQL = "$EDMAuto_Path\Scripts\deploy_eam_allver.sql"
#$EAM_OUT = "$EDMAuto_Path\Logs\eam_out.txt"
#If(Test-Path $EAM_DEPLOY_SQL)
#{
# cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U $SA_AltName -P $SAPW -i "`"$EAM_DEPLOY_SQL`"" -o $EAM_OUT
#}
#If (Test-Path $EAM_OUT)
#{
# $eamOut = Get-Content -Path $EAM_OUT
# Remove-Item -Path $EAM_OUT
#
# If ($eamOut -match "error" -or $eamOut -match "Msg")
# {
# $EAM_Error = $true
# Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tEAM Deployment was attempted, and may have failed - review the following output:`r`n`r`n$eamOut")
# }
# Else
# {
# Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tEAM Deployment was SUCCESS - EAM output:`r`n`r`n$eamOut")
# }
#
#
#}
}
Else
{
$PathCheck = "PATH NOT FOUND!!! $Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"
}
# Removing EAM error check per version 1.1.2
#If ($Error -or $PathCheck -or $EAM_Error -or !$eamOut)
If ($Error -or $PathCheck)
{
$message = "!!!ERROR DETECTED!!!`n`n"+
"Review the PowerShell console for any error messages the may have occurred.`n`n"+
"Install Log File Can Be Found: $EDMAuto_Path\Logs\`n`n"+
"Send questions or concerns to the email address: EDM_DAN_SQL@wellsfargo.com "
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tError Detected - Review error details.. `r`n"`
+"`t`t`tThis error comes when process was connecting to newly installed instance to disable SA and create SA replacement...`r`n`r`n$Error$PathCheck`r`n`r`nEXITING SCRIPT`r`n")
}
Else
{
$message = "!!!INSTALL SUCCESS!!!`n`n"+
"Post Install Steps include the following:`n"+
"SQL Server Port Changed to Static Port # $TCP_Port`n"+
"Fire Wall updated with new port number.`n"+
"SA Account has been disabled.`n"+
"$SA_AltName has been created.`n"+
#"EAM Objects have been deployed.`n`n"+ #EAM Objects are no longer part of this install package as of version 1.1.2
"Install Log File Can Be Found:`n`t$EDMAuto_Path\Logs\`n`n"+
"Please verify your install of $SQLInstance`n`n"
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`t$message")
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
}
exit
########################
#STEP 7 END
########################
<#
.SYNOPSIS
The purpose of this script is to gather details from the DBA installer to customize their SQL Server install. This script will produce a
configuration ini file and will launch a SQL Server silent Install. After the silent instal, a basic check is done to ensure the new instance
is created. If the new instance exists, the port number is changed from dynamic to static, firewall rules are updated with the new port information,
sa account is disabled, and the polkj11 account is created.
.DESCRIPTION
This script will gather the following information:
1.) Named or Default instance
2.) SQL Server Service Account Name
3.) SQL Server Service Account Password
4.) SQL Agent Service Account Name
5.) SQL Agent Service Account Password
6.) Integrated SErvices Service Account Name
7.) Integrated Service Service Account Password
8.) Alternate SA account Name
9.) SA / Alternate SA Password
10.) DBA Privileged Group -- See variable below for list of groups
.NOTES
File Name : EDMSQLServer2012_Install.ps1
Company : Wells Fargo
Dept : CTD Enterprise Data Management
Author : John Aspenleiter - jaspenle@wellsfargo.com
Requires : The script must be run as Administrator, and access to the following nas shares so media can be copied locally
OXMOOR \\wfsaloxnsf01\DAN_BWB_SOFT_01
SV2 \\mns2nsf701z1.wellsfargo.net\dan_pwv_soft_01
TEMPE \\azt2nsf701z1.wellsfargo.net\dan_bwz_soft_01
SILAS \\wfsncsilsnsf02\DAN_PWS_SOFT_01
STL \\wfsmotemrnnf02\DAN_PWL_SOFT_01
WEC \\wfsncwecnnf01\DAN_PWW_SOFT_01
Create Date: 3/9/2013
.LINK
N/A
.EXAMPLE
.INPUTTYPE
.RETURNVALUE
A configuration ini file is created and placed on local drive. A silent install is then kicked off.
.REVISION HISTORY
Version : 1.0.0
Date : 4/26/2013
Author : John Aspenleiter
Description: The script was first developed on 3/9/2013, the final version used for the first release
is this date. All future releases will be subject to version control.
Version : 1.1.0
Date : 5/10/2013
Author : John Aspenleiter
Description: Added the following enhancements:
1. Displays port information to the end user.
2. Added Standard / Enterprise edition support - new form to choose from.
3. Drive selection supports mount points.
4. Drive selection form now shows the exact install paths
5. SSIS checkbox - you now have the option to install SSIS.
6. Deployment of EAM objects for EDM's login provisioning workflow.
Version : 1.1.1
Date : 7/15/2013
Author : John Aspenleiter
Description: BUG FIX - Error found when installing to a server where there is only a C drive present.
Found an elseif not capturing the c drive correctly. In the "getdriveinfo" function,
I changed the elseif from:
ElseIf ($rootdrive -eq "C:\")
TO
ElseIf ($rootdrive -eq "C:")
Version : 1.2.0
Date : 8/16/2013
Author : Brent Johnston
Description: ENHANCEMENT - Commented out the EAM object deployments because that will no longer be
part of the install package
Version : 1.2.1
Date : 4/17/2014
Author : Brent Johnston
Description: BUG FIX - Fixing variable scoping issue discovered during Windows 2012 testing
Version : 1.2.3 & 1.2.4
Date : 12/09/2015 & 5/26/2015
Author : J Aspenleiter
Description: Updating NAS filer location for where install media is stored.
Version : 1.2.5
Date : 11/25/2015
Author : J. Aspenleiter
Description: Updated -- $stl_nas = "wfsmotemrnnf02.bank.corp"
$wec_nas = "wfsncwecnnf01.bank.corp"
For some reason, ent.wfb.bank.corp stopped working - not gonna look into it much....
Updated the GPO check with the correct GPO names that should be used.
CPS_CORP_SQL_2008_2012_2014
CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide
Version : 1.2.6
Date : 05/20/2016
Author : D. Leone
Description: Updated - included new privilegd groups based on LOB and Environment:
LOB Env Domain ADGroupName
DVE PRD AD-ENT PRV_EDM_FA_SRV_DVE_SA_PRD
DVE NONPRD AD-ENT PRV_EDM_FA_SRV_DVE_SA_NONPRD
CorpTech PRD AD-ENT PRV_EDM_FA_SRV_CorpTech_SA_PRD
CorpTech NP AD-ENT PRV_EDM_FA_SRV_CorpTech_SA_NP
CommBank PRD AD-ENT PRV_EDM_FA_SRV_CommBank_SA_PRD
CommBank NP AD-ENT PRV_EDM_FA_SRV_CommBank_SA_NP
Lending PRD AD-ENT PRV_EDM_FA_SRV_Lending_SA_PRD
Lending NP AD-ENT PRV_EDM_FA_SRV_Lending_SA_NP
WIM PRD AD-ENT PRV_EDM_FA_SRV_WIM_SA_PRD
WIM NP AD-ENT PRV_EDM_FA_SRV_WIM_SA_NP
ALL ALL ALL PRV_EDM_FA_SRV_SQLServiceAccounts
DVE, CommBank ALL ALL PRV_EDM_DA_SRV_COMMBKGDBAdmins
DVE, CorpTech ALL ALL PRV_EDM_DA_SRV_CTFHDBADMINS
DVE ALL ALL PRV_EDM_DA_SRV_DANDBADMINS
DVE, WIM ALL ALL PRV_EDM_DA_SRV_WFADBADMINS
DVE, Lending ALL ALL PRV_EDM_DA_SRV_LENDINGDBADMINS
ALL ALL ALL PRV_EDM_DA_SRV_WFISDBAdmins
#>
clear
#Let's also clear out ANY errors that may have been passed from the console to the scirpt.
If($Error){$Error.Clear()}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#ACTIVE DIRECTORY DOMAIN
Set-Variable -Name AD_Domain -Value (Get-Content env:UserDomain) -Scope Script
#INSTALL DRIVE LETTER
Set-Variable -Name Install_Drive -Scope Script
#DATA DRIVE LETTER
Set-Variable -Name Data_Drive -Scope Script
#DEFAULT INSTALL PATH - for both binaries, and data... For DATA PATH - mount points will override this default path if chosen.
Set-Variable -Name Default_SQL_Path -Value "\Program Files\Microsoft SQL Server" -Scope Script
#DEFAULT WOW DIR
Set-Variable -Name Default_Wow_Path -Value "\Program Files (x86)\Microsoft SQL Server" -Scope Script
#SQLADMIN Folder Admin Path (ROOT FOLDER)
Set-Variable -Name SQLAdmin_Folder -Value "SQLAdmin" -Scope Script
#EDMAUTO Folder
Set-Variable -Name EDMAuto_Folder -Value "EDMAuto" -Scope Script
#INSTALL media Folder: - this is now being set in the Getedition Function
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script
#UpdateSource media Folder:
Set-Variable -Name SS_UpdateSource_Folder -Value "Media\SQL2012UpdateSource" -Scope Script
#config Folder:
Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#config file path: - this is now being set in the GetEdition Function
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2012 Installation" -Scope Script
#Centralized Log File Path:
Set-Variable -Name CntrlLogPath -Value "\\wfsmotemrnnf02\DAN_PWL_SOFT_01\EDMSqlSvrInstall\Logs\" -Scope Script
#TimsStamp for log file
Set-Variable -Name datetimestamp -Value (Get-Date -uformat %Y%m%d%H%M%S) -Scope Script
#Log File Prefix Name:
Set-Variable -Name LogFilePrefix -Value "SqlSvr2012" -Scope Script
Set-Variable -Name MediaLogFile -Value $CntrlLogPath$LogFilePrefix"_MediaCopy_"$datetimestamp".txt" -Scope Script
Set-Variable -Name InstallLogFile -Value $CntrlLogPath$LogFilePrefix"_Install_"$datetimestamp".txt" -Scope Script
Set-Variable -Name MessageStamp -Value "$(Get-Date -format 'u')`r`n$([Environment]::UserName)`r`n$([Environment]::UserDomainName)`r`n$([Environment]::MachineName)`r`n`r`n" -Scope Script
Set-Variable -Name LogMessage -Value $MessageStamp -Scope Script
Set-Variable -Name MinSupportRelease -Value "R11" -Scope Script
#Setting the Array for all the Previleged Groups we currently allow.
$PREV_Options = `
@(`
"AD-ENT\PRV_EDM_FA_SRV_SQLServiceAccounts"`
,"AD-ENT\PRV_EDM_DA_SRV_COMMBKGDBAdmins"`
,"AD-ENT\PRV_EDM_DA_SRV_CTFHDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_DANDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_TISOPSDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_WFADBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_LENDINGDBADMINS"`
,"AD-ENT\PRV_EDM_DA_SRV_WFISDBAdmins"`
,"AD-ENT\PRV_EDM_DA_SRV_DASDBAdmins"`
,"AD-ENT\DTCS_EBS_EDM_SQL"`
)
#Setting the Array for the alternative SA accounts that EDM supports - setting this to an array to support multiple choices:
$SA_Options = `
@(`
"polkj11"`
)
#LOBS to determine what groups
[array]$LOBS = "DVE", "CorpTech", "CommBank", "Lending","WIM"
#LOBS to determine what groups
[array]$Environments = "PROD", "NON-PROD"
$LOBChoice = "DVE"
$EnvChoice = "PROD"
################ MEDIA LOCATIONS #########################
<#
OXMOOR \\aloxnsf701z1.wellsfargo.net\DAN_BWB_SOFT_01
SV2 \\mns2nsf701z1.wellsfargo.net\dan_pwv_soft_01
TEMPE \\azt2nsf701z1.wellsfargo.net\dan_bwz_soft_01
SILAS \\ncslnsf701z1.wellsfargo.net\DAN_PWS_SOFT_01
STL \\wfsmotemrnnf02.bank.corp\DAN_PWL_SOFT_01
WEC \\wfsncwecnnf01.bank.corp\DAN_PWW_SOFT_01
##############Message Box Values######################
0: OK
1: OK Cancel
2: Abort Retry Ignore
3: Yes No Cancel
4: Yes No
5: Retry Cancel
#>
$oxmoor_nas = "aloxnsf701z1.wellsfargo.net"
$sv2_nas = "mns2nsf701z1.wellsfargo.net"
$tempe_nas = "azt2nsf701z1.wellsfargo.net"
$silas_nas = "ncslnsf701z1.wellsfargo.net"
$stl_nas = "wfsmotemrnnf02.bank.corp"
$wec_nas = "wfsncwecnnf01.bank.corp"
$oxmoor_path = "\\$oxmoor_nas\DAN_BWB_SOFT_01\"
$sv2_path = "\\$sv2_nas\dan_pwv_soft_01\"
$tempe_path = "\\$tempe_nas\dan_bwz_soft_01\"
$silas_path = "\\$silas_nas\DAN_PWS_SOFT_01\"
$stl_path = "\\$stl_nas\DAN_PWL_SOFT_01\"
$wec_path = "\\$wec_nas\DAN_PWW_SOFT_01\"
################ MEDIA LOCATIONS #########################
#set a local script variable to the name of the server we're installing on.
Set-Variable -Name hostname -Scope Script
$hostname = Get-Content env:computername
#FUNCTIONS BEGIN
Function GetLobEnvironment
{
#This came as an after thought - so, we're adding it as it's own form since too many variables are dependant on this...
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2014EE" -Scope Script - ENTERPRISE EDITON
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2014SE" -Scope Script - STANDARD EDITON
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2014 Installation" -Scope Script
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SQL Server LOB & Environment Selection"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
$script:LOBInstall = $objListLOBDropDown.SelectedItem
$script:EnvInstall = $objListEnvDropDown.SelectedItem
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
<#
$objEdtnLbl = New-Object System.Windows.Forms.Label
$objEdtnLbl.Location = New-Object System.Drawing.Size(10,20)
$objEdtnLbl.autosize = $true
$objEdtnLbl.Text = "Please select the edition of SQL Server 2014 you wish to install."
$objForm.Controls.Add($objEdtnLbl)
$objEdtnListBox = New-Object System.Windows.Forms.ListBox
$objEdtnListBox.Location = New-Object System.Drawing.Point(10,40)
$objEdtnListBox.Size = New-Object System.Drawing.Size(150,50)
$objEdtnListBox.Items.add("ENTERPRISE EDITION")
$objEdtnListBox.Items.add("STANDARD EDITION")
$objEdtnListBox.tabindex = 0
$objEdtnListBox.SetSelected(0,$true)
$objForm.Controls.Add($objEdtnListBox)
#>
#CREATE THE LABEL
#$y+=30
$objLbl_10 = New-Object System.Windows.Forms.Label
$objLbl_10.Location = New-Object System.Drawing.Size(10,40) #(0,$y)
$objLbl_10.Autosize = $true
$objLbl_10.Text = "LOB:"
$objForm.Controls.Add($objLbl_10)
$objLbl_11 = New-Object System.Windows.Forms.Label
$objLbl_11.Location = New-Object System.Drawing.Size(150,40) #(150,$y)
$objLbl_11.Autosize = $true
$objLbl_11.Text = "Environment:"
$objForm.Controls.Add($objLbl_11)
#Create the select Boxes
$objListLOBDropDown = new-object System.Windows.Forms.ComboBox
$objListLOBDropDown.Location = new-object System.Drawing.Point(10,60)
$objListLOBDropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($LOB in $LOBS) {
[void] $objListLOBDropDown.Items.Add($LOB)
}
$objListLOBDropDown.SelectedIndex = $LOBS.IndexOf($LOBChoice)
$objForm.Controls.Add($objListLOBDropDown)
$objListEnvDropDown = new-object System.Windows.Forms.ComboBox
$objListEnvDropDown.Location = new-object System.Drawing.Point(150,60)
$objListEnvDropDown.Size = new-object System.Drawing.Size(130,30)
ForEach ($Environ in $Environments) {
[void] $objListEnvDropDown.Items.Add($Environ)
}
$objListEnvDropDown.SelectedIndex = $Environments.IndexOf($EnvChoice)
$objForm.Controls.Add($objListEnvDropDown)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
If (!$exit) # -and $SS_Setup_Folder)
{
#Set-Variable -Name SS_Setup_Folder -Value $SS_Setup_Folder -Scope Script
#Set-Variable -Name Form_Name -Value $Form_Name -Scope Script
Return $true
}
Else
{
Exit
}
}
Function GetEdition
{
#This came as an after thought - so, we're adding it as it's own form since too many variables are dependant on this...
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script - ENTERPRISE EDITON
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012SE" -Scope Script - STANDARD EDITON
#Set-Variable -Name Form_Name -Value "EDM SQL Server 2012 Installation" -Scope Script
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SQL Server Edition Selection"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
If ($objEdtnListBox.SelectedItem.ToString() -eq "ENTERPRISE EDITION")
{
$script:SS_Setup_Folder = "Media\SQL2012EE"
$script:Form_Name = "EDM SQL Server 2012 Enterprise Edition Installation"
}
Else
{
$script:SS_Setup_Folder = "Media\SQL2012SE"
$script:Form_Name = "EDM SQL Server 2012 Standard Edition Installation"
}
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objEdtnLbl = New-Object System.Windows.Forms.Label
$objEdtnLbl.Location = New-Object System.Drawing.Size(10,20)
$objEdtnLbl.autosize = $true
$objEdtnLbl.Text = "Please select the edition of SQL Server 2012 you wish to install."
$objForm.Controls.Add($objEdtnLbl)
$objEdtnListBox = New-Object System.Windows.Forms.ListBox
$objEdtnListBox.Location = New-Object System.Drawing.Point(10,40)
$objEdtnListBox.Size = New-Object System.Drawing.Size(150,50)
$objEdtnListBox.Items.add("ENTERPRISE EDITION")
$objEdtnListBox.Items.add("STANDARD EDITION")
$objEdtnListBox.tabindex = 0
$objEdtnListBox.SetSelected(0,$true)
$objForm.Controls.Add($objEdtnListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
If (!$exit -and $SS_Setup_Folder)
{
Set-Variable -Name SS_Setup_Folder -Value $SS_Setup_Folder -Scope Script
Set-Variable -Name Form_Name -Value $Form_Name -Scope Script
Return $true
}
Else
{
Exit
}
}
Function GetRelease
{
[int]$minInt = $MinSupportRelease.Replace("R","")
$IsSupported = $true
If (Test-Path "HKLM:\SOFTWARE\AutoBuild")
{
$Release = (Get-Item -Path "hklm:\SOFTWARE\AutoBuild").GetValue("AutoBuildVersion")
$ReleaseInt = ($Release.split("."))[0]
If ($ReleaseInt.StartsWith("R"))
{
#Ok we can test it - it starts with a R, if it doesn't, it's probably an SSO - which is not supported.
[int]$ReleaseInt = $ReleaseInt.Replace("R","")
If ([int]$ReleaseInt -lt [int]$minInt )
{
$IsSupported = $false
}
}
Else
{
$IsSupported = $false
}
}
Else
{
$Release = "UNKNOWN"
}
New-Object PSObject -Property @{
Version = [string]$Release;
IsSupported = [bool]$IsSupported
}
}
Function GetDriveInfo
{
#get all drives available on the system that have over 1 GB free
$drives = Get-WmiObject -Class Win32_Volume | Where-Object {$_.FreeSpace -gt 1073741824}
Foreach ($drive in $drives)
{
$rootdrive = ($drive.Caption).TrimEnd("\")
If ($rootdrive -ne "C:" -and $AvailDrives -notlike "*$rootdrive*" )
{
#We only want drives that are not the C drive, and we don't want duplicates...
#When you grab a list of drives from the volume class, you may get multiples of the same
#drive due to mount points.
If(!$AvailDrives){$AvailDrives = $rootdrive}
Else {$AvailDrives += ","+$rootdrive}
}
ElseIf ($rootdrive -eq "C:")
{
$AvailDrive = $rootdrive
}
}
#We need to see if there is a previous installation of SQL Server - if so, we need to pick the drive that already has the
#binaries - they don't have an option now....
If (Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup")
{
$installDrive = (((Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup").GetValue("SQLPath")).Split("\"))[0]
}
#CREATE THE DRIVE FORM:
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "SELECT DRIVES AND/OR MOUNT POINTS"
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(125,400)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click(
{
$script:Install_Drive=$objBinListBox.SelectedItem.ToString()
;$script:Data_Drive=$objDataListBox.SelectedItem.ToString()
;$script:InstallSqlPath=$objBinListBox.SelectedItem+$Default_SQL_Path
;$script:InstallWowPath=$objBinListBox.SelectedItem+$Default_Wow_Path
;If ($($objDataListBox.SelectedItem).Length -lt 3)
{
$script:InstallDataPath = $objDataListBox.SelectedItem+$Default_SQL_Path
}
Else
{
$script:InstallDataPath = $objDataListBox.SelectedItem
}
;$objForm.Close()
}
)
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(220,400)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objBinListBox = New-Object System.Windows.Forms.ListBox
$objBinListBox.Location = New-Object System.Drawing.Point(10,40)
$objBinListBox.Size = New-Object System.Drawing.Size(300,80)
$objBinListBox.Add_Click({
$objBinDisplayOut.Text = $objBinListBox.SelectedItem+$Default_SQL_Path;
$objWowDisplayOut.Text = $objBinListBox.SelectedItem+$Default_Wow_Path
})
$objBinListBox.tabindex = 0
#DEFAULT INSTALL PATH - for both binaries, and data... For DATA PATH - mount points will override this default path if chosen.
#Set-Variable -Name Default_SQL_Path -Value "\Program Files\Microsoft SQL Server" -Scope Script
#DEFAULT WOW DIR
#Set-Variable -Name Default_Wow_Path -Value "\Program Files (x86)\Microsoft SQL Server" -Scope Script
#"INSTANCEDIR=`"$Install_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSQLDATADIR=`"$Data_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSHAREDDIR=`"$Install_Drive\Program Files\Microsoft SQL Server`"`r`n"+
#"INSTALLSHAREDWOWDIR=`"$Install_Drive\Program Files (x86)\Microsoft SQL Server`"`r`n"+
If ($installDrive)
{
#We found that there is already an install of sql server, we're going to use the exact same binary drive as before.
$objBinListBox.Items.add($installDrive) | Out-Null
}
Else
{
If ($AvailDrives)
{
foreach($AvailDrive in $AvailDrives.Split(","))
{
$objBinListBox.Items.add($AvailDrive) | Out-Null
}
}
Else
{
$objBinListBox.Items.add($AvailDrive) | Out-Null
}
}
$objBinListBox.SetSelected(0,$true)
$objForm.Controls.Add($objBinListBox)
$objBinDisplay = New-Object System.Windows.Forms.Label
$objBinDisplay.Location = New-Object System.Drawing.Size(10,230)
$objBinDisplay.autosize = $true
$objBinDisplay.Text = "INSTALLING SHARED BINARIES TO:"
$objForm.Controls.Add($objBinDisplay)
$objBinDisplayOut = New-Object System.Windows.Forms.Label
$objBinDisplayOut.Location = New-Object System.Drawing.Size(20,250)
$objBinDisplayOut.autosize = $true
$objBinDisplayOut.Text = $objBinListBox.SelectedItem+$Default_SQL_Path
$objForm.Controls.Add($objBinDisplayOut)
$objWowDisplay = New-Object System.Windows.Forms.Label
$objWowDisplay.Location = New-Object System.Drawing.Size(10,270)
$objWowDisplay.autosize = $true
$objWowDisplay.Text = "INSTALLING SHARED WOW BINARIES TO ROOT PATH:"
$objForm.Controls.Add($objWowDisplay)
$objWowDisplayOut = New-Object System.Windows.Forms.Label
$objWowDisplayOut.Location = New-Object System.Drawing.Size(20,290)
$objWowDisplayOut.autosize = $true
$objWowDisplayOut.Text = $objBinListBox.SelectedItem+$Default_Wow_Path
$objForm.Controls.Add($objWowDisplayOut)
$objBinLabel = New-Object System.Windows.Forms.Label
$objBinLabel.Location = New-Object System.Drawing.Size(10,20)
#$objBinLabel.Size = New-Object System.Drawing.Size(380,20)
$objBinLabel.Autosize = $true
$objBinLabel.Text = "Select the drive or mount point you wish to install binaries and shared components:"
$objForm.Controls.Add($objBinLabel)
$objDataListBox = New-Object System.Windows.Forms.ListBox
$objDataListBox.Location = New-Object System.Drawing.Point(10,140)
$objDataListBox.Size = New-Object System.Drawing.Size(300,80)
$objDataListBox.Add_Click({
If ($($objDataListBox.SelectedItem).Length -lt 3)
{
$script:dataInstallPath = $objDataListBox.SelectedItem+$Default_SQL_Path
}
Else
{
$script:dataInstallPath = $objDataListBox.SelectedItem
};$objDataDisplayOut.Text = $dataInstallPath
})
$objDataListBox.tabindex = 1
If ($AvailDrives)
{
foreach($AvailDrive in $AvailDrives.Split(","))
{
$objDataListBox.Items.add($AvailDrive) | Out-Null
}
}
Else
{
$objDataListBox.Items.add($AvailDrive) | Out-Null
}
$objDataListBox.SetSelected(0,$true)
$objForm.Controls.Add($objDataListBox)
$objDataDisplay = New-Object System.Windows.Forms.Label
$objDataDisplay.Location = New-Object System.Drawing.Size(10,320)
$objDataDisplay.autosize = $true
$objDataDisplay.Text = "INSTALLING SYSTEM DATABASE FILES TO ROOT PATH:"
$objForm.Controls.Add($objDataDisplay)
$objDataDisplayOut = New-Object System.Windows.Forms.Label
$objDataDisplayOut.Location = New-Object System.Drawing.Size(20,340)
$objDataDisplayOut.autosize = $true
$data_selected_item = $objDataListBox.SelectedItem
If ([int]$data_selected_item.Lenth -lt 3)
{
$script:dataInstallPath = $data_selected_item+$Default_SQL_Path
}
Else
{
$script:dataInstallPath = $data_selected_item
}
$objDataDisplayOut.Text = $dataInstallPath
$objForm.Controls.Add($objDataDisplayOut)
$objDataLabel = New-Object System.Windows.Forms.Label
$objDataLabel.Location = New-Object System.Drawing.Size(10,120)
$objDataLabel.Size = New-Object System.Drawing.Size(380,20)
$objDataLabel.Text = "Select the drive or mount point you wish to install SYSTEM DATA files to:"
$objForm.Controls.Add($objDataLabel)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#if variables aren't set, then they must have pressed the X button on the form.
if (!$Install_Drive -or !$Data_Drive){exit}
if ($Install_Drive -and $Data_Drive)
{
Set-Variable -Name Install_Drive -value $Install_Drive -Scope Script
Set-Variable -Name Data_Drive -Value $Data_Drive -Scope Script
Set-Variable -Name InstallSqlPath -Value $InstallSqlPath -Scope Script
Set-Variable -Name InstallWowPath -Value $InstallWowPath -Scope Script
Set-Variable -Name InstallDataPath -Value $InstallDataPath -Scope Script
$true
}
}
Function GetMedia
{
<#
If this function is called, it's been detected that a local copy of the media doesn't exist.
The purpose of this function is to ping each NAS filer and detect the least amount of response time. This will
decide which NAS filer to use copying the media down. If the local folders are not created yet, we will create them for you
and then copy down the required media to install SQL Server.
#>
$nas_hosts = @($oxmoor_nas,$sv2_nas,$tempe_nas,$silas_nas,$stl_nas,$wec_nas)
$nas_paths = @($oxmoor_path,$sv2_path,$tempe_path,$silas_path,$stl_path,$wec_path)
foreach ($nas_host in $nas_hosts)
{
[string]$ResponsetimeTEST = (Test-Connection $nas_host -Count 1).ResponseTime
If (!$response_time)
{
[string]$response_time = [string]$ResponsetimeTEST
$NASHOST = $nas_host
}
else
{
If ([string]$ResponsetimeTEST -lt [string]$response_time)
{
[string]$response_time = [string]$ResponsetimeTEST
$NASHOST = $nas_host
}
}
}
Foreach ($nas_path in $nas_paths)
{
If ($NASHOST -eq $nas_path.split("\")[2])
{
$NAS_COPY_FROM = $nas_path
}
}
#Create the objects that do the copy - I picked these objects to do the copy to show progress to the installer.
$FOF_CREATEPROGRESSDLG = "&H0&"
$objShell = New-Object -ComObject "Shell.Application"
#copied these variable definitions here to help understand which each one means... Leaving here for future work.
# $SQLAdmin_Path = $Install_Drive+"\"+$SQLAdmin_Folder
# $EDMAuto_Path = $SQLAdmin_Path+"\"+$EDMAuto_Folder
# $InstallMedia_Path = $EDMAuto_Path+"\"+$SS_Setup_Folder
# $UpdateSource_Path = $EDMAuto_Path+"\"+$SS_UpdateSource_Folder
#$srcFile = $NAS_COPY_FROM+"EDMAuto\*.*"
#$DestLocation = $EDMAuto_Path
#Let's check all the possible paths that need to exist...
If(!(Test-Path "$EDMAuto_Path\Logs")){New-Item -type directory -Path "$EDMAuto_Path\Logs" | Out-Null}
If(!(Test-Path "$EDMAuto_Path\Scripts"))
{
New-Item -type directory -Path "$EDMAuto_Path\Scripts" | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\Scripts\*.*"
$objFolder = $objShell.NameSpace("$EDMAuto_Path\Scripts")
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
Else
{
Remove-Item -Path "$EDMAuto_Path\Scripts\*.*" -Force -Recurse
#Let's get everything there everytime this runs - we need to be sure everything in here is up to date.
$srcFile = $NAS_COPY_FROM+"EDMAuto\Scripts\*.*"
$objFolder = $objShell.NameSpace("$EDMAuto_Path\Scripts")
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
If(!(Test-Path $SetupEXE))
{
If (Test-Path $InstallMedia_Path){Remove-Item -Path $InstallMedia_Path -Force -Recurse}
New-Item -type directory -Path $InstallMedia_Path | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\$SS_Setup_Folder\*.*"
$objFolder = $objShell.NameSpace($InstallMedia_Path)
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
# if we made it to this point, then we successfully copied the stuff that we care about...
If (Test-Path $CntrlLogPath){$MessageStamp | Out-File $MediaLogFile}
}
If(!(Test-Path $UpdateSource_Path))
{
New-Item -type directory -Path $UpdateSource_Path | Out-Null
$srcFile = $NAS_COPY_FROM+"EDMAuto\$SS_UpdateSource_Folder\*.*"
$objFolder = $objShell.NameSpace($UpdateSource_Path)
$objFolder.CopyHere($srcFile, $FOF_CREATEPROGRESSDLG)
}
}
Function GetPrevInst
{
<#
This function checks to see if there is existing SQL Server instances on this host. If so - it warns the installer of the installed instance names so
they do not choose an instance name already installed. Also, it will check to see if there is a default instance, if so, the program will not
allow the choice to install a default instance.
#>
#This path exists no matter what version of sql server is installed - check it. If it's there, we need to check
#values.... We'll present them to the console.
If (Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL")
{
$ValueNames = (Get-Item -Path "hklm:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL").getvaluenames()
If ($ValueNames)
{
ForEach ($ValueName in $ValueNames)
{
#Create a comma delimited variable to break up into an array.
If (!$instancenames)
{
$instancenames = $ValueName
}
Else
{
$instancenames += ","+$ValueName
}
}
}
}
If ($instancenames){$instancenames}
}
Function IntroForm
{
<#
This is the initial form to detect if the install of SQL Server will be
a named or default install.
#>
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $Form_Name
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
#$objForm.Size = New-Object System.Drawing.Size(400,220)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(125,100)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click({$script:x=$objListBox.SelectedItem.ToString();$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(220,100)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$Options = @("DEFAULT","NAMED")
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Point(10,50)
$objListBox.Size = New-Object System.Drawing.Size(100,40)
$objListBox.tabindex = 0
foreach($option in $Options)
{
$objListBox.Items.add($option) | Out-Null
}
$objListBox.SetSelected(0,$true)
$objForm.Controls.Add($objListBox)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(380,20)
$objLabel.Text = "Are you installing a `"Named`" or `"Default`" instance of SQL Server 2012?"
$objForm.Controls.Add($objLabel)
#$objTextBox = New-Object System.Windows.Forms.TextBox
#$objTextBox.Multiline = $true
#$objTextBox.Location = New-Object System.Drawing.Size(10,40)
#$objTextBox.Size = New-Object System.Drawing.Size(260,200)
#$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#if named instance is seleced, we'll set the value to true
#if $x isn't set, then they must have pressed the X button on the form.
if (!$x){exit}
if ($x -eq "NAMED"){$true}else{$false}
if ($Exit){exit}
}
Function MainForm ($Named)
{
<#
Now that we know if this is a named or default install, we'll gather the rest of the info.
1.) Named or Default instance
2.) SQL Server Service Account Name
3.) SQL Server Service Account Password
4.) SQL Agent Service Account Name
5.) SQL Agent Service Account Password
6.) Integrated Services Service Account Name
7.) Integrated Service Service Account Password
8.) SQL Server Full Text Account Name
9.) SQL Server Full Text Account Password
10.) DBA Privileged Group:
o PRV_EDM_DA_SRV_COMMBKGADMINS
o PRV_EDM_DA_SRV_CTFHDBADMINS
o PRV_EDM_DA_SRV_DANDBADMINS
o PRV_EDM_DA_SRV_TISOPSDBADMINS
o PRV_EDM_DA_SRV_WFADBADMINS
o PRV_EDM_DA_SRV_LENDINGDBADMINS
o PRV_EDM_DA_SRV_WFISDBAdmins
11.) SA Password
#>
#CREATE THE FORM:
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $Form_Name
#$objForm.Size = New-Object System.Drawing.Size(400,600)
$objForm.Autosize = $true
$objForm.AutosizeMode = "GrowAndShrink"
$objForm.AutoScroll = $true
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$ToolTip = New-Object System.Windows.Forms.ToolTip
$ToolTip.BackColor = [System.Drawing.Color]::LightGoldenrodYellow
$ToolTip.IsBalloon = $true
$ToolTip.InitialDelay = 150
$ToolTip.ReshowDelay = 150
########################################
#QUESTION 1 - Named Instance or Default
########################################
#CREATE THE LABEL
$objLbl_1 = New-Object System.Windows.Forms.Label
$objLbl_1.Location = New-Object System.Drawing.Size(0,10)
$objLbl_1.Autosize = $true
#SET the (X,Y) Y coordinate of location to a variable... Starting it at LINE 30...
$y = 10
If ($Named)
{
If ($default)
{
$Text = "A DEFAULT INSTANCE ALREADY EXISTS.`n"
}
Else
{
$Text = "You have selected to run a NAMED INSTANCE install.`n"
}
#lets add on to the $text - if there are existing instance names, let's let the installer know they can't use these names for this install:
If ($instanceArray)
{
Foreach($Instance in $instanceArray)
{
if ($Instance -ne "MSSQLSERVER")
{
If (!$textAdd)
{
$textAdd = "`nExisting Named Instances Detected! Do not use the following instance names for your install:`n`n$Instance"
$y+=30
}
Else
{
$textAdd += "`n$Instance"
$y+=10
}
}
}
$Text+=$textAdd
}
$Text+="`n`nInstance Name:"
$y+=38
}
Else
{
$Text = "You have selected to run a DEFAULT INSTANCE install."
$y+=10
}
$objLbl_1.Text = $Text
$objForm.Controls.Add($objLbl_1)
#LINE = This Label ends on line 50
#If named instance, add the text box to capture named instance
#SET THE "TAB ORDER OF THE CURSOR" Increment this var one after each control
$tabindex = 0
#CREATE THE TEXT BOX
If ($Named)
{
$y+=50
$objTextBox_Named = New-Object System.Windows.Forms.TextBox
$objTextBox_Named.Location = New-Object System.Drawing.Size(10,$y)
$objTextBox_Named.Size = New-Object System.Drawing.Size(250,10)
#Setting MAX Length of instance name to 16 - this is the most it can handle.
$objTextBox_Named.MaxLength = 16
$objTextBox_Named.tabindex = $tabindex
$objForm.Controls.Add($objTextBox_Named)
$tabindex++
$Named_Tip_Msg = "The instance name must be 16 characters or less, `nstart with a letter, not have any spaces or special `ncharacters and not use certain reserved words."
$ToolTip.SetToolTip($objTextBox_Named, $Named_Tip_Msg)
}
#LINE = This text box is on line 60
########################################
#QUESTION 2 - SQL Server Service Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_2 = New-Object System.Windows.Forms.Label
$objLbl_2.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_2.Autosize = $true
$objLbl_2.Text = "SQL Server SERVICE Account Name:"
$objForm.Controls.Add($objLbl_2)
#LINE 90
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SvcAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_SvcAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SvcAcctName.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SvcAcctName.Text = "AD-ENT\"
$objTxtBx_SvcAcctName.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SvcAcctName)
$tabindex++
$AcctName_Tip_Msg = "This is a domain account which is a member of the Windows `ngroup associated with the SQL GPO applied to the server."
$ToolTip.SetToolTip($objTxtBx_SvcAcctName, $AcctName_Tip_Msg)
#LINE 110
########################################
#QUESTION 3 - SQL Server Service Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_3 = New-Object System.Windows.Forms.Label
$objLbl_3.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_3.Autosize = $true
$objLbl_3.Text = "SQL Server SERVICE Account Password:"
$objForm.Controls.Add($objLbl_3)
#LINE 140
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SvcAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SvcAcctPW.PasswordChar = "*"
$objTxtBx_SvcAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SvcAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SvcAcctPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SvcAcctPW)
$tabindex++
$PW_Tip_Msg = "This is the password which was prepared before starting the installation.`n"`
+"The default password for domain accounts must be changed. The new password `n"`
+"must follow WF password construction rules."
$ToolTip.SetToolTip($objTxtBx_SvcAcctPW, $PW_Tip_Msg)
#LINE 160
########################################
#QUESTION 4 - SQL Server Agent Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_4 = New-Object System.Windows.Forms.Label
$objLbl_4.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_4.Autosize = $true
$objLbl_4.Text = "SQL Server AGENT Account Name:"
$objForm.Controls.Add($objLbl_4)
#LINE 180
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_AgtAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_AgtAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_AgtAcctName.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_AgtAcctName.Text = "AD-ENT\"
$objTxtBx_AgtAcctName.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_AgtAcctName)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_AgtAcctName, $AcctName_Tip_Msg)
#LINE 200
########################################
#QUESTION 5 - SQL Server Agent Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_5 = New-Object System.Windows.Forms.Label
$objLbl_5.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_5.Autosize = $true
$objLbl_5.Text = "SQL Server AGENT Account Password:"
$objForm.Controls.Add($objLbl_5)
#LINE 230
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_AgtAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_AgtAcctPW.PasswordChar = "*"
$objTxtBx_AgtAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_AgtAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_AgtAcctPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_AgtAcctPW)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_AgtAcctPW, $PW_Tip_Msg)
#LINE 250
########################################
#QUESTION 5.1 - Install SSIS?
########################################
#CREATE THE LABEL
$y+=30
$objLbl_ssis = New-Object System.Windows.Forms.Label
$objLbl_ssis.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_ssis.Autosize = $true
$objLbl_ssis.Text = "Check this box if you want to Install SSIS:"
$objForm.Controls.Add($objLbl_ssis)
#CREATE THE CHECK BOX
$y+=20
$objChkBx_SSISInstall = New-Object System.Windows.Forms.CheckBox
$objChkBx_SSISInstall.Location = New-Object System.Drawing.Size(10,$y)
$objChkBx_SSISInstall.Size = New-Object System.Drawing.Size(250,10)
$objChkBx_SSISInstall.tabindex = $tabindex
#$objTxtBx_SSISAcctName.ReadOnly = $false
$objChkBx_SSISInstall.Add_Click(
{
If ($objChkBx_SSISInstall.Checked)
{
$objTxtBx_SSISAcctName.ReadOnly = $false; $objTxtBx_SSISAcctName.Text = "AD-ENT\"; $objTxtBx_SSISAcctPW.ReadOnly = $false
}
Else
{
$objTxtBx_SSISAcctName.ReadOnly = $true; $objTxtBx_SSISAcctPW.ReadOnly = $true; $objTxtBx_SSISAcctName.Text = ""; $objTxtBx_SSISAcctPW.Text = ""
}
}
)
$objForm.Controls.Add($objChkBx_SSISInstall)
$tabindex++
$ToolTip.SetToolTip($objChkBx_SSISInstall, "SSIS is only needed if you are running or scheduling SSIS packages from this instance. `nMaintenance Plans will work without this component installed.")
#LINE 300
########################################
#QUESTION 6 - SSIS Service Account Name
########################################
#CREATE THE LABEL
$y+=30
$objLbl_6 = New-Object System.Windows.Forms.Label
$objLbl_6.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_6.Autosize = $true
$objLbl_6.Text = "SSIS Service Account Name:"
$objForm.Controls.Add($objLbl_6)
#LINE 280
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SSISAcctName = New-Object System.Windows.Forms.TextBox
$objTxtBx_SSISAcctName.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SSISAcctName.Size = New-Object System.Drawing.Size(250,10)
#$objTxtBx_SSISAcctName.Text = "AD-ENT\"
$objTxtBx_SSISAcctName.tabindex = $tabindex
$objTxtBx_SSISAcctName.ReadOnly = $true
$objForm.Controls.Add($objTxtBx_SSISAcctName)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_SSISAcctName, $AcctName_Tip_Msg)
#LINE 300
########################################
#QUESTION 7 - SSIS Service Account Password
########################################
#CREATE THE LABEL
$y+=30
$objLbl_7 = New-Object System.Windows.Forms.Label
$objLbl_7.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_7.Autosize = $true
$objLbl_7.Text = "SSIS Service Account Password:"
$objForm.Controls.Add($objLbl_7)
#LINE 330
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SSISAcctPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SSISAcctPW.PasswordChar = "*"
$objTxtBx_SSISAcctPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SSISAcctPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SSISAcctPW.tabindex = $tabindex
$objTxtBx_SSISAcctPW.ReadOnly = $true
$objForm.Controls.Add($objTxtBx_SSISAcctPW)
$tabindex++
$ToolTip.SetToolTip($objTxtBx_SSISAcctPW, $PW_Tip_Msg)
#LINE 350
###########################################
#QUESTION 8 - Alternative SA Account Selection:
###########################################
#CREATE THE LABEL
$y+=30
$objLbl_8 = New-Object System.Windows.Forms.Label
$objLbl_8.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_8.Autosize = $true
$objLbl_8.Text = "SA Replacement Account:"
$objForm.Controls.Add($objLbl_8)
#CREATE THE COMBO BOX
$y+=20
# $SA_Options
$objListBox_SaAccnt = New-Object System.Windows.Forms.Listbox
$objListBox_SaAccnt.Location = New-Object System.Drawing.Point(10,$y)
$objListBox_SaAccnt.Size = New-Object System.Drawing.Size(200,20)
$objListBox_SaAccnt.tabindex = $tabindex
$tabindex++
foreach($option in $SA_Options)
{
$objListBox_SaAccnt.Items.add($option) | Out-Null
}
#$objComboBox.SetSelected(0,$true)
$objListBox_SaAccnt.SelectedIndex = 0
$objForm.Controls.Add($objListBox_SaAccnt)
$SaAccnt_Tip_Msg = "This is the replacement for the SA account. `nThis account will be created during installation. `nThe SA account will be disabled during the installation."
$ToolTip.SetToolTip($objListBox_SaAccnt, $SaAccnt_Tip_Msg)
########################################
#QUESTION 9 - SA / Alternative SA Password
########################################
#CREATE THE LABEL
$y+=20
$objLbl_11 = New-Object System.Windows.Forms.Label
$objLbl_11.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_11.Autosize = $true
$objLbl_11.Text = "SA Replacement Account Password:"
$objForm.Controls.Add($objLbl_11)
#LINE 530
#CREATE THE TEXT BOX
$y+=20
$objTxtBx_SAPW = New-Object System.Windows.Forms.MaskedTextBox
$objTxtBx_SAPW.PasswordChar = "*"
$objTxtBx_SAPW.Location = New-Object System.Drawing.Size(10,$y)
$objTxtBx_SAPW.Size = New-Object System.Drawing.Size(250,10)
$objTxtBx_SAPW.tabindex = $tabindex
$objForm.Controls.Add($objTxtBx_SAPW)
$tabindex++
$SAPW_Tip_Msg = "Enter a password following WF password construction rules."
$ToolTip.SetToolTip($objTxtBx_SAPW, $SAPW_Tip_Msg)
#LINE 550
###########################################
#QUESTION 10 - DBA Privileged Group to add:
###########################################
<#
#CREATE THE LABEL
$y+=30
$objLbl_10 = New-Object System.Windows.Forms.Label
$objLbl_10.Location = New-Object System.Drawing.Size(0,$y)
$objLbl_10.Autosize = $true
$objLbl_10.Text = "Select one or more privileged groups to be added to the SQL Server sysadmin server role:"
$objForm.Controls.Add($objLbl_10)
#LINE 480
#CREATE THE COMBO BOX
$y+=20
# $PREV_Options = `
# @(`
# "AD-ENT\PRV_EDM_DA_SRV_COMMBKGADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_CTFHDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_DANDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_TISOPSDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_WFADBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_LENDINGDBADMINS"`
# ,"AD-ENT\PRV_EDM_DA_SRV_WFISDBAdmins"`
# )
$objListBox_PrivGrp = New-Object System.Windows.Forms.Listbox
$objListBox_PrivGrp.Location = New-Object System.Drawing.Point(10,$y)
$objListBox_PrivGrp.Size = New-Object System.Drawing.Size(300,100)
$objListBox_PrivGrp.SelectionMode = "MultiExtended"
$objListBox_PrivGrp.tabindex = $tabindex
$tabindex++
foreach($option in $PREV_Options)
{
$objListBox_PrivGrp.Items.add($option) | Out-Null
}
#$objComboBox.SetSelected(0,$true)
$objListBox_PrivGrp.SelectedIndex = 0
$objForm.Controls.Add($objListBox_PrivGrp)
$PrivGrp_Tip_Msg = "Hold down the CTRL or SHIFT keys to select multiple groups."
$ToolTip.SetToolTip($objListBox_PrivGrp, $PrivGrp_Tip_Msg)
#>
#LINE 500
#####################################
#OK BUTTON - LINE 600
#####################################
$y+=40 #100
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(145,$y)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "Next"
$OKButton.tabindex = $tabindex
$OKButton.Add_Click({$script:Config_INI = Compile_INI})
$objForm.Controls.Add($OKButton)
$tabindex++
#######################################
#CANCEL BUTTON - LINE 600
######################################
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(240,$y)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.tabindex = $tabindex
$CancelButton.Add_Click({$objForm.Close();$Exit=$true})
$objForm.Controls.Add($CancelButton)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
if ($Exit){exit}
return $Config_INI
}
Function Compile_INI
{
<#
This funciton will not only compile the configuration file, but before that, it does a few checks to ensure the
properties we are passing it will work for the install. If they don't pass, we will send the installer back to the
main form.
We are going to set a main bit to be used to ensure the set of checks are used... If the user "x"s out of the main form
after the checks run, the next validation window pops - we don't want that to happen.
#>
Set-Variable -name VALIDATION_CHECK -Value $true -Scope Script
If ($objTextBox_Named)
{
Set-Variable -Name InstanceName -Value $objTextBox_Named.text -Scope Script
}
Else
{
Set-Variable -Name InstanceName -Value "MSSQLSERVER" -Scope Script
}
If ($objChkBx_SSISInstall.Checked)
{
Set-Variable -Name SSIS_INSTALL -Value $true -Scope Script
}
#Let's double check that they aren't using an instance name that already exists on this system....
Foreach($Instance in $instanceArray)
{
if ($Instance -eq $InstanceName)
{
#Something didn't get populated - pop a message.
[Windows.Forms.MessageBox]::Show("$InstanceName - THIS INSTANCE NAME IS ALREADY IN USE ON THIS SYSTEM!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
}
<#
Let's now check to ensure the instance name abides by the Microsoft Naming Convention for Instance Names.
* The first character in the instance name must be a letter.
* Embedded spaces or other special characters are not allowed in instance names.
The backslash (\), comma (,), colon (:), semi-colon (;), single quote ('),
ampersand (&), and at sign (@) are also not allowed.
#>
If ($InstanceName)
{
If ($instancename.Substring(0,1) -match "[0-9]")
{
[Windows.Forms.MessageBox]::Show("$InstanceName - THE FIRST CHARACTER IN THE INSTANCE NAME CANNOT BE A NUMBER!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
$SpecChars = @('!','"','£','$','%','&','^','`*','(',')','@','=','+','¬','`','\','<','>','.','`?','/',':',';','#','~',"'",' ','-')
ForEach ($SpecChar in $SpecChars)
{
If ($instancename -like '*'+$SpecChar+'*'){$SpecCharFound=$true}
}
If ($SpecCharFound)
{
[Windows.Forms.MessageBox]::Show("$InstanceName - A SPECIAL CHARACTER WAS DETECTED IN THE INSTANCE NAME - THEY ARE NOT ALLOWED!", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
}
#get all selected items in list box
<#
If ($objListBox_PrivGrp.SelectedItem)
{
ForEach ($PrivGrp in $objListBox_PrivGrp.SelectedItems)
{
If (!$PrivGrps)
{
$PrivGrps = "`""+$PrivGrp+"`""
}
Else
{
$PrivGrps += " `""+$PrivGrp+"`""
}
}
}
#>
$PrivGrps ='"PRV_EDM_FA_SRV_SQLServiceAccounts" "PRV_EDM_DA_SRV_WFISDBAdmins" '
switch ($LOBInstall){
DVE {$PrivGrps +='"PRV_EDM_DA_SRV_COMMBKGDBAdmins" "PRV_EDM_DA_SRV_CTFHDBADMINS" "PRV_EDM_DA_SRV_DANDBADMINS" "PRV_EDM_DA_SRV_WFADBADMINS" "PRV_EDM_DA_SRV_LENDINGDBADMINS"'; break}
CorpTech {$PrivGrps +='"PRV_EDM_DA_SRV_CTFHDBADMINS"'; break}
CommBank {$PrivGrps +='"PRV_EDM_DA_SRV_COMMBKGDBAdmins"'; break}
Lending {$PrivGrps +='"PRV_EDM_DA_SRV_LENDINGDBADMINS"'; break}
WIM {$PrivGrps +='"PRV_EDM_DA_SRV_WFADBADMINS"'; break}
default {$PrivGrps += ""; break}
}
if($EnvInstall -eq "PROD" -and $AD_Domain -eq 'AD-ENT')
{
switch ($LOBInstall){
DVE {$PrivGrps +=' "PRV_EDM_FA_SRV_DVE_SA_PRD"'; break}
CorpTech {$PrivGrps +=' "PRV_EDM_FA_SRV_CorpTech_SA_PRD"'; break}
CommBank {$PrivGrps +=' "PRV_EDM_FA_SRV_CommBank_SA_PRD"'; break}
Lending {$PrivGrps +=' "PRV_EDM_FA_SRV_Lending_SA_PRD"'; break}
WIM {$PrivGrps +=' "PRV_EDM_FA_SRV_WIM_SA_PRD"'; break}
default {$PrivGrps += ""; break}
}
}
elseif($EnvInstall -eq "NON-PROD" -and $AD_Domain -eq 'AD-ENT')
{
switch ($LOBInstall){
DVE {$PrivGrps +=' "PRV_EDM_FA_SRV_DVE_SA_NONPRD"'; break}
CorpTech {$PrivGrps +=' "PRV_EDM_FA_SRV_CorpTech_SA_NP"'; break}
CommBank {$PrivGrps +=' "PRV_EDM_FA_SRV_CommBank_SA_NP"'; break}
Lending {$PrivGrps +=' "PRV_EDM_FA_SRV_Lending_SA_NP"'; break}
WIM {$PrivGrps +=' "PRV_EDM_FA_SRV_WIM_SA_NP"'; break}
default {$PrivGrps += ""; break}
}
}
#make sure everything is populated - if not, pop a message saying they have to fill it out...
If (
($InstanceName -eq '')-or
($objTxtBx_SvcAcctName.text -eq '') -or
($objTxtBx_SvcAcctPW.text -eq '') -or
($objTxtBx_AgtAcctPW.text -eq '') -or
($objTxtBx_AgtAcctName.text -eq '') -or
($SSIS_INSTALL -and
(($objTxtBx_SSISAcctPW.text -eq '') -or
($objTxtBx_SSISAcctName.text -eq ''))) -or
(!$PrivGrps) -or
($objTxtBx_SAPW.text -eq '')
)
{
#Something didn't get populated - pop a message.
[Windows.Forms.MessageBox]::Show("All Fields Must Be Populated. Check install form.", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
ELSE
{
#SEtting the variable scope to the script level so we can comem back to this and show the installer what was used.
Set-Variable -Name SrvAcctName -Value $objTxtBx_SvcAcctName.text -Scope Script
Set-Variable -Name SvcAcctPW -Value $objTxtBx_SvcAcctPW.text -Scope Script
Set-Variable -Name AgtAcctName -Value $objTxtBx_AgtAcctName.text -Scope Script
Set-Variable -Name AgtAcctPW -Value $objTxtBx_AgtAcctPW.text -Scope Script
If ($SSIS_INSTALL)
{
Set-Variable -Name SSISAcctPW -Value $objTxtBx_SSISAcctPW.text -Scope Script
Set-Variable -Name SSISAcctName -Value $objTxtBx_SSISAcctName.text -Scope Script
}
Else
{
Set-Variable -Name SSISAcctPW -Value "N/A - WILL NOT INSTALL SSIS" -Scope Script
Set-Variable -Name SSISAcctName -Value "N/A - WILL NOT INSTALL SSIS" -Scope Script
}
Set-Variable -Name SA_AltName -Value $objListBox_SaAccnt.SelectedItem -Scope Script
#Set-Variable -Name FTAcctPW -Value $objTxtBx_FTAcctPW.text -Scope Script
#Use this line if we ONLY want to use what is select.
#it now uses a value they can type in... - override the options....
#Set-Variable -Name PrivGrp -Value $objComboBox_PrivGrp.SelectedItem.ToString() -Scope Script
Set-Variable -Name PrivGroups -Value $PrivGrps -Scope Script
Set-Variable -Name SAPW -Value $objTxtBx_SAPW.text -Scope Script
}
#Let's check to see if *-ENT\* is part of the account names - these have to be domain accounts.
If (
$SrvAcctName -notlike "*-ENT\*" -or
$AgtAcctName -notlike "*-ENT\*" -or
($SSIS_INSTALL -and
$SSISAcctName -notlike "*-ENT\*")
)
{
[Windows.Forms.MessageBox]::Show("All Service Accounts Must Be Domain Accounts.", `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
#Now that we know they are domain accounts - let's make sure the login and passowrds are valid.
$SrvAccntCHK = Test-ADCredentials -username $SrvAcctName -password $SvcAcctPW -domain ($SrvAcctName.split("\"))[0] -AccntType "SERVICE ACCT"
$AgtAcctCHK = Test-ADCredentials -username $AgtAcctName -password $AgtAcctPW -domain ($AgtAcctName.split("\"))[0] -AccntType "AGENT ACCT"
If ($SSIS_INSTALL)
{
$SSISAccCHK = Test-ADCredentials -username $SSISAcctName -password $SSISAcctPW -domain ($SSISAcctName.split("\"))[0] -AccntType "SSIS ACCT"
}
$AcctChkMessage = ""
If ((!$SSIS_INSTALL)-and
($SrvAccntCHK.IsValid -eq "False" -or
$AgtAcctCHK.IsValid -eq "False")
)
{
$AcctChkMessage = "ACCOUNT VALIDATION CHECK FAILED! VERIFY LOGINS AND PASSWORDS ARE CORRECT!`n"`
+$SrvAccntCHK.AccntType+"`t"+$SrvAccntCHK.username+"`tIsValid = "+$SrvAccntCHK.IsValid+"`n"`
+$AgtAcctCHK.AccntType+"`t"+$AgtAcctCHK.username+"`tIsValid = "+$AgtAcctCHK.IsValid+"`n"
}
If (($SSIS_INSTALL) -and
($SSISAccCHK.IsValid -eq "False" -or
$SrvAccntCHK.IsValid -eq "False" -or
$AgtAcctCHK.IsValid -eq "False"))
{
$AcctChkMessage = "ACCOUNT VALIDATION CHECK FAILED! VERIFY LOGINS AND PASSWORDS ARE CORRECT!`n"`
+$SrvAccntCHK.AccntType+"`t"+$SrvAccntCHK.username+"`tIsValid = "+$SrvAccntCHK.IsValid+"`n"`
+$AgtAcctCHK.AccntType+"`t"+$AgtAcctCHK.username+"`tIsValid = "+$AgtAcctCHK.IsValid+"`n"`
+$SSISAccCHK.AccntType+"`t"+$SSISAccCHK.username+"`tIsValid = "+$SSISAccCHK.IsValid+"`n"
}
If($AcctChkMessage)
{
[Windows.Forms.MessageBox]::Show($AcctChkMessage, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
Set-Variable -name VALIDATION_CHECK -Value $false -Scope Script
return
}
$script:INI_OUT = ";SQL Server 2012 Configuration File`r`n"+
"[OPTIONS]`r`n"+
"INSTANCENAME=`"$InstanceName`"`r`n"+
"INSTANCEID=`"$InstanceName`"`r`n"+
"SQLSVCACCOUNT=`"$SrvAcctName`"`r`n"+
"AGTSVCACCOUNT=`"$AgtAcctName`"`r`n"+
#"ISSVCACCOUNT=`"$SSISAcctName`"`r`n"+
"SQLSYSADMINACCOUNTS=$PrivGroups`r`n"+
"SQLSVCPASSWORD=`"$SvcAcctPW`"`r`n"+
"AGTSVCPASSWORD=`"$AgtAcctPW`"`r`n"+
#"ISSVCPASSWORD=`"$SSISAcctPW`"`r`n"+
"SAPWD=`"$SAPW`"`r`n"+
"INSTANCEDIR=`"$InstallSqlPath`"`r`n"+
"INSTALLSQLDATADIR=`"$InstallDataPath`"`r`n"+
"INSTALLSHAREDDIR=`"$InstallSqlPath`"`r`n"+
"INSTALLSHAREDWOWDIR=`"$InstallWowPath`"`r`n"+
"UpdateSource=`"$UpdateSource_Path`"`r`n`r`n"+
"ACTION=`"Install`"`r`n"+
"IACCEPTSQLSERVERLICENSETERMS=`"True`"`r`n"+
"ENU=`"True`"`r`n"+
#"FEATURES=SQLEngine,Replication,CONN,IS,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"+
"X86=`"False`"`r`n"+
"ERRORREPORTING=`"False`"`r`n"+
"SQMREPORTING=`"False`"`r`n"+
"UpdateEnabled=`"True`"`r`n"+
"SQLSVCSTARTUPTYPE=`"Automatic`"`r`n"+
"AGTSVCSTARTUPTYPE=`"Automatic`"`r`n"+
#"ISSVCSTARTUPTYPE=`"Automatic`"`r`n"+
#"BROWSERSVCSTARTUPTYPE=`"Disabled`"`r`n"+
"TCPENABLED=`"1`"`r`n"+
"NPENABLED=`"1`"`r`n"+
"SQLCOLLATION=`"SQL_Latin1_General_CP1_CI_AS`"`r`n"+
"SECURITYMODE=`"SQL`"`r`n"
#We only need the browser service if it's a named instance....
If ($InstanceName -ne "MSSQLSERVER")
{
$script:INI_OUT += "BROWSERSVCSTARTUPTYPE=`"Automatic`"`r`n"
}
Else
{
$script:INI_OUT += "BROWSERSVCSTARTUPTYPE=`"Disabled`"`r`n"
}
If ($SSIS_INSTALL)
{
$script:INI_OUT += "FEATURES=SQLEngine,Replication,CONN,IS,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"+
"ISSVCACCOUNT=`"$SSISAcctName`"`r`n"+
"ISSVCPASSWORD=`"$SSISAcctPW`"`r`n"+
"ISSVCSTARTUPTYPE=`"Automatic`"`r`n"
}
Else
{
$script:INI_OUT += "FEATURES=SQLEngine,Replication,CONN,BC,SDK,SSMS,ADV_SSMS,SNAC_SDK`r`n"
}
#Close the main form
$objForm.Close()
Return $script:INI_OUT
}
##commenting out this block of code, could be used later... I'm leaving it in cause it did work to launch the setup this way.
#Function JobKickOff
#{
# #I've set the folder path of the setup.exe folder to a variable, along with the config file path.
# #this was done in the event we want to allow other locations for execution.
#
# $SetupFolder = $SQLAdmin_Path+$SS_Setup_Folder
# $ScriptBlock = {param($SetupFolder_, $ConfigFile_) cd $SetupFolder_;.\setup.exe /configurationfile=$ConfigFile_ /q `
# /IACCEPTSQLSERVERLICENSETERMS}
#
#
#
# Start-Job -name SS2K12_Install -ScriptBlock $ScriptBlock -Arg $SetupFolder, $ConfigFile | Out-Null
#
#}
#
#Function Col-Jobs
#<#Function Col-Jobs
# This function will monitor the sql install and flash a message to the powershell console. If the install doesn't finish within one hour
# The script will stop monitoring the install and exit the powershell script - a message will flash to the console stating this.
##>
#{
# #any error lurking around, clear them.. we have to test this in this function
# $Error.Clear()
#
# $i = 0
# $messageout = $now + "SQL Install Running"
# Write-Host $messageout
# Do
# {
# $CompleteJobs = get-job | where {$_.State -ne "Running"}
#
#
# If ($CompleteJobs)
# {
# ForEach ($compJob in $CompleteJobs)
# {
# $output += Receive-Job $compJob.id
# #any errors that may have came from this:
# $output += $Error
# Remove-Job $compJob.id
# }
# clear
# $time = Get-Date | Out-String
# If ($Error)
# {
# $messageout += "`n`n"+ $time + "!!!!!SQL Install Completed With Errors`n`n"
# }
# Else
# {
# $messageout += "`n`n"+ $time + " SQL Install Complete"
# }
# Write-Host $messageout
# }
#
# $Anyjobs = Get-Job
#
# If ($Anyjobs)
# {
# Start-Sleep -Seconds 10
# $messageout += "."
# Clear
# Write-Host $messageout
# }
#
# ++$i
# $Anyjobs = Get-Job
# }
# Until
# (
# (!$Anyjobs) -or ($i -eq 3600) #giving the install 1 hour....
# )
#
# If (!$output)
# {
# clear
# $time = Get-Date | Out-String
# $messageout += "`n`n" + $time + " SQL Install running over 1 hour - Poweshell Script Ending. - Setup.exe will continue to run..."
# Write-Host $messageout
# $output = "!!!!!!!!!!!SQL INSTALL STILL RUNNING!!!!!!!!!!!"
# }
#
# $output
#}
Function ConfirmInstall
{
$objFormConf = New-Object System.Windows.Forms.Form
$objFormConf.Text = $Form_Name
$objFormConf.Autosize = $true
$objFormConf.AutosizeMode = "GrowAndShrink"
$objFormConf.AutoScroll = $true
#$objForm.Size = New-Object System.Drawing.Size(400,220)
$objFormConf.StartPosition = "CenterScreen"
$objFormConf.KeyPreview = $True
$objFormConf.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objFormConf.Close()}})
$ConfMsg0 = "If this information is correct, you are now ready to install."
$ConfMsg1 = "LOB:`n"+
"Environment:`n"+
"Instance Name:`n"+
"Service Acct Name:`n"+
"Service Acct PW:`n"+
"Agent Acct Name:`n"+
"Agent Acct PW:`n"+
#"SSIS Acct Name:`n"+
#"SSIS Acct PW:`n"+
"SA Alt Acct Name:`n"+
"SA PW:`n"
#"Privledged Group(s)"
If ($SSIS_INSTALL)
{
$ConfMsg1 += "SSIS Acct Name:`n"+
"SSIS Acct PW:`n"+
"Privledged Group(s)`n"+
"added to SysAdmin`n"+
"role:"
}
Else
{
$ConfMsg1 += "Privledged Group(s)`n"+
"added to SysAdmin`n"+
"role:"
}
$ConfMsg2 = "$LOBInstall`n"+
"$EnvInstall`n"+
"$InstanceName`n"+
"$SrvAcctName`n"+
"*****`n"+
"$AgtAcctName`n"+
"*****`n"+
#"$SSISAcctName`n"+
#"*****`n"+
"$SA_AltName`n"+
"*****`n"
#$PrivGroups.Replace(" ","`n") +"`n"
If ($SSIS_INSTALL)
{
$ConfMsg2 += "$SSISAcctName`n"+
"*****`n"+
$PrivGroups.Replace(" ","`n") +"`n"
}
Else
{
$ConfMsg2 += $PrivGroups.Replace(" ","`n") +"`n"
}
#Get the line count of number of groups...
$count = 0
ForEach ($group in $PrivGroups.Split(" ")){$count+=10}
#LINE COUNT = 180 $count = number of groups - add that to 180. That's where we put the next line.
$linecount = (220 + $count) #(180 + $count)
$ConfMsg3 = "Click `"Install`" to install SQL Server with the provided information."
$objLbl0_conf = New-Object System.Windows.Forms.Label
$objLbl0_conf.Location = New-Object System.Drawing.Size(10,20)
$objLbl0_conf.Autosize = $true
$objLbl0_conf.Text = $ConfMsg0
$objFormConf.Controls.Add($objLbl0_conf)
$objLbl1_conf = New-Object System.Windows.Forms.Label
$objLbl1_conf.Location = New-Object System.Drawing.Size(10,40)
$objLbl1_conf.Autosize = $true
$objLbl1_conf.Text = $ConfMsg1
$objFormConf.Controls.Add($objLbl1_conf)
$objLbl2_conf = New-Object System.Windows.Forms.Label
$objLbl2_conf.Location = New-Object System.Drawing.Size(130,40)
$objLbl2_conf.Autosize = $true
$objLbl2_conf.Text = $ConfMsg2
$objFormConf.Controls.Add($objLbl2_conf)
$objLbl3_conf = New-Object System.Windows.Forms.Label
$objLbl3_conf.Location = New-Object System.Drawing.Size(10,$linecount)
$objLbl3_conf.Autosize = $true
$objLbl3_conf.Text = $ConfMsg3
$objFormConf.Controls.Add($objLbl3_conf)
$linecount += 40
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,$linecount)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "INSTALL"
$OKButton.tabindex = 1
#$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$OKButton.Add_Click({$script:x2=$true;$objFormConf.Close()})
$objFormConf.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(170,$linecount)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "CANCEL"
$CancelButton.tabindex = 2
$CancelButton.Add_Click({$objFormConf.Close();$Exit=$true})
$objFormConf.Controls.Add($CancelButton)
$objFormConf.Topmost = $True
$objFormConf.Add_Shown({$objFormConf.Activate()})
[void] $objFormConf.ShowDialog()
#if these conditions are met, then we're killing it.
If ($Exit -or !($script:x2))
{
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tConfirmation Form - Canceled - Exiting Script.`r`n")
exit
}
Else
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tConfirmation Form - Accepted`r`n")
}
}
Function SetPort
{
$BasePath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server"
If (Test-Path $BasePath)
{
#get all the installed instances
$SubKeys = (Get-Item -Path $BasePath).getsubkeynames()
ForEach ($SubKey in $SubKeys)
{
#roll through all the instances and see what ports they are using - EXCEPT the newly installed instance...
If ($SubKey -like "MSSQL*.*" -and $SubKey -notlike "MSSQL*.$InstanceName")
{
$PortItems = Get-ItemProperty -Path "$BasePath\$SubKey\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
$TcpDynPort = $PortItems.TcpDynamicPorts
$TcpStatPort = $PortItems.TcpPort
If ($TcpStatPort)
{
If(!$UsedPorts){$UsedPorts = $TcpStatPort}
Else {$UsedPorts += ","+$TcpStatPort}
}
If ($TcpDynPort)
{
If(!$UsedPorts){$UsedPorts = $TcpDynPort}
Else {$UsedPorts += ","+$TcpDynPort}
}
}
#While we're here, let's get the base key for the newly instance - we need to use it later
ElseIf($SubKey -like "MSSQL*.$instancename")
{
$BaseKey_installed_path = "$BasePath\$SubKey\MSSQLServer\SuperSocketNetLib\Tcp\IPAll"
}
}
If ($UsedPorts)
{
ForEach ($UsedPort in $UsedPorts.Split(","))
{
If($UsedPort -gt 11000 -and $UsedPort -lt 11999)
{
if(!$HighestUsedPort)
{
$HighestUsedPort = $UsedPort
}
Elseif($HighestUsedPort -lt $UsedPort)
{
$HighestUsedPort = $UsedPort
}
}
}
}
If (!$HighestUsedPort){$HighestUsedPort=11000}
$NextAvailPort = [int]$HighestUsedPort+1
#We now know what port is free to use, let's set the newly installed SQL Server to that port
Set-ItemProperty -Path $BaseKey_installed_path -Name TcpDynamicPorts -Value ''
Set-ItemProperty -Path $BaseKey_installed_path -Name TcpPort -Value $NextAvailPort
#Let's return this as an output - we're going to need this for setting the firewall...
$NextAvailPort
}
}
Function RestartSQLServices
{
#Let's get the service objects set for the installed instance
$AgentService = get-service | where-object {$_.DisplayName -eq "SQL Server Agent ($InstanceName)" }
$SQLService = get-service | where-object {$_.DisplayName -eq "SQL Server ($InstanceName)" }
If ($AgentService.Status -eq 'Running')
{
"Stopping the "+$AgentService.DisplayName+" Service..." | Write-Host
#if it's running, let's stop it...
$AgentService.Stop()
#let's give it a few seconds.. then we'll check it's status again...
Start-Sleep -Seconds 3
$counter = 0
#looping 9 times - pausing 3 sec between loops.
While ($counter -lt 10)
{
$AgentService.Refresh()
If ($AgentService.Status -eq 'Stopped'){$counter = 100}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
If ($AgentService.Status -eq 'Stopped' -and $SQLService.Status -eq 'Running')
{
"The "+$AgentService.DisplayName+" Service is "+$AgentService.Status | Write-Host
"Stopping the "+$SQLService.DisplayName+" Service..." | Write-Host
#Ok - it's now time to stop the SQL Server Service...
$SQLService.Stop()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$SQLService.Refresh()
If ($SQLService.Status -eq 'Stopped'){$counter = 100}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
#Let's Restart SQL SErver Service
If ($SQLService.Status -eq 'Stopped')
{
"The "+$SQLService.DisplayName+" Service is "+$SQLService.Status | Write-Host
"Starting the "+$SQLService.DisplayName+" Service..." | Write-Host
$SQLService.Start()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$SQLService.Refresh()
If ($SQLService.Status -eq 'Running'){$counter = 100;$restart=$true}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
If ($AgentService.Status -eq 'Stopped' -and $SQLService.Status -eq 'Running')
{
"The "+$SQLService.DisplayName+" Service is "+$SQLService.Status | Write-Host
"Starting the "+$AgentService.DisplayName+" Service..." | Write-Host
#Ok - it's now time to stop the SQL Server Service...
$AgentService.Start()
Start-Sleep -Seconds 3
$counter = 0
While ($counter -lt 10)
{
$AgentService.Refresh()
If ($AgentService.Status -eq 'Running'){$counter = 100;"The "+$AgentService.DisplayName+" Service is "+$AgentService.Status | Write-Host}
Else {Start-Sleep -Seconds 3;$counter++}
}
}
Return $restart
}
Function SQLServicePing
{
<#
In order to see if the newly installed sql server REALLY got installed,
because there is no good return code to analyze from the installer, we're going to
analyze the service. See if it's there, and running. If so, we can connect to it and
finish up our installation.
Things we've already attemptted - a SQL Ping doesn't work efficiently, and checking the registry will return
unpredictable results due to how soon the registry is refreshed with the newly added information to this scripts shell.
this function returns true if new instance is running, and false if not found, or not running.
#>
Try
{
$SQLService = get-service -ErrorAction SilentlyContinue | where-object {$_.DisplayName -eq "SQL Server ($InstanceName)" }
}
Catch [Exception]
{
#Service name not found - return false
Return $false
}
If ($SQLService)
{
If ($SQLService.status -eq "Running"){Return $true}Else{Return $false}
}
Else
{
Return $false
}
}
Function Test-ADCredentials
{
Param($username, $password, $domain, $AccntType)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain)
New-Object PSObject -Property @{
UserName = $username;
IsValid = $pc.ValidateCredentials($username, $password).ToString();
AccntType = $AccntType
}
}
Function Log-Message ([bool]$Write, [string]$Msg)
{
Set-Variable -Name LogMessage -value "$LogMessage$Msg" -Scope Script
#Send Message to console:
Write-Host $Msg
If ($Write)
{
If (Test-path $CntrlLogPath) {$LogMessage | Out-File -FilePath $InstallLogFile}
#Local Log Folder - may not exist due to how the program logic got to this point.
#test variables, and then test path - if all there, we'll have a local copy of the log as well.
If ($EDMAuto_Path)
{
$LocalLog_Path = $EDMAuto_Path+"\Logs\"
If (Test-Path $LocalLog_Path)
{
$localLogfile = $LocalLog_Path+$LogFilePrefix+"_Install_"+$datetimestamp+".txt"
#$localLogfile
$LogMessage | Out-File -FilePath $localLogfile
Write-Host "Log file of this install can be found: $localLogfile"
}
}
}
}
#################
# FUNCTIONS END
#################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#####################
# PROGRAM LOGIC BEGIN
#####################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#############
#STEP 0 BEGIN
#############
<#
It is vital this script is run as admin - if not we must send a message and kill the script. this will not work unless run as admin.
#>
$Admin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")
If (!$Admin)
{
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tScript was runas NON Admin authority - Error - killing script.`r`n")
$message = "!!!ERROR!!!`n`n"+
"Install MUST be run as administrator.`n`n"+
"Run this with runas administrator."
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Error) | Out-Null
# We will only store a central log file for this one... if we can't get to it, we'll just flash this message on the
Exit
}
$Release = GetRelease
If (!($Release.IsSupported))
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! Release Level $($Release.Version).`r`n")
$message = "!!!WARNING - Release Version!!! $($Release.Version)`n`n"+
"Install has been fully tested on $MinSupportRelease or greater.`n`nContinue at your own risk..."
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name,[Windows.Forms.MessageBoxButtons]::OKCancel, [Windows.Forms.MessageBoxIcon]::Warning)
# We will only store a central log file for this one... if we can't get to it, we'll just flash this message on the
If ($OUTPUT-eq"Cancel" -or !$OUTPUT){Exit}
}
#Check to see if GPO is there...
$RSOP_GPO_SQL = Get-WmiObject -Namespace root\RSOP\Computer -Class RSOP_GPO | Where-Object {$_.name -like "CPS_CORP_SQL_2008_2012_2014"}
$RSOP_GPO_SQL_OR = Get-WmiObject -Namespace root\RSOP\Computer -Class RSOP_GPO | Where-Object {$_.name -like "CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide"}
If (!$RSOP_GPO_SQL)
{
$message = "!!!WARNING - GPO Check Failed. CPS_CORP_SQL_2008_2012_2014 Policy was not detected.`n`n"+
"This instance you are installing will not be following the EDM standard and may not function correctly without the CPS_CORP_SQL_2008_2012_2014 GPO applied.`n`nDo you want to CANCEL this installation?`n"
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::YesNo, [Windows.Forms.MessageBoxIcon]::Warning)
If ($OUTPUT-eq"Yes" -or !$OUTPUT){Exit}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! CPS_CORP_SQL_2008_2012_2014 Policy GPO was not detected. Installation continuing.`r`n")
}
If (!$RSOP_GPO_SQL_OR)
{
$message = "!!!WARNING - GPO Check Failed. CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide Policy was not detected.`n`n"+
"This instance you are installing will not be following the EDM standard and may not function correctly without the CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide GPO applied.`n`nDo you want to CANCEL this installation?`n"
$OUTPUT=[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::YesNo, [Windows.Forms.MessageBoxIcon]::Warning)
If ($OUTPUT-eq"Yes" -or !$OUTPUT){Exit}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t!!!WARNING!!! CPS_PowerShell_ExecPolicy_RemoteSigned_OverRide Policy GPO was not detected. Installation continuing.`r`n")
}
#############
#STEP 0 END
#############
<#
#############
#STEP 1 BEGIN
#############
2 variables were set at the very top of this script - we need to ensure the paths exist, otherwise
everything collected will not work, and setup will not kick off.
#############
#>
#Let's check the paths... Default is D drive... If d doesn't exist, we'll check C
#Base Admin Path
#Set-Variable -Name SQLAdmin_Path -Value "D:\SQLAdmin\" -Scope Script
#install media location:
#Set-Variable -Name SS_Setup_Folder -Value "SQLServer2012EE\" -Scope Script
#config file path:
#Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#install media should be here - if it's not, they may not have copied it down...
##SQLADMIN Folder Admin Path (ROOT FOLDER)
#Set-Variable -Name SQLAdmin_Folder -Value "SQLAdmin" -Scope Script
#
##SQLADMIN Folder Admin Path
#Set-Variable -Name EDMAuto_Folder -Value "EDMAuto" -Scope Script
#
##install media location:
#Set-Variable -Name SS_Setup_Folder -Value "Media\SQL2012EE" -Scope Script
#
##UpdateSource media location:
#Set-Variable -Name SS_UpdateSource_Folder -Value "Media\SQL2012UpdateSource" -Scope Script
If(GetLobEnvironment){
#We have to set the edition of sql server we want to install - has to be the first step.
If (GetEdition)
{
#The following function sets the binary and data drives for the install...
If (getDriveInfo)
{
$SQLAdmin_Path = $Install_Drive+"\"+$SQLAdmin_Folder
$EDMAuto_Path = $SQLAdmin_Path+"\"+$EDMAuto_Folder
$LocalLog_Path = $EDMAuto_Path+"\Logs"
$InstallMedia_Path = $EDMAuto_Path+"\"+$SS_Setup_Folder
$UpdateSource_Path = $EDMAuto_Path+"\"+$SS_UpdateSource_Folder
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe following paths will be used for the install:`r`n"`
+"`t`t`t$InstallMedia_Path`r`n`t`t`t$UpdateSource_Path`r`n")
#$SQLAdmin_Path
#$EDMAuto_Path
#$InstallMedia_Path
#$UpdateSource_Path
#"C:\Program Files\Microsoft SQL Server\110\Tools\Binn"
}
}
}
$SetupEXE = "$InstallMedia_Path\Setup.EXE"
If (!(Test-Path $SetupEXE))
{
$message = "SQL Server Install Media - COPY PROCESS.`n`n"+
"INSTALL MEDIA WILL BE COPIED DOWN - DO NOT CANCEL COPY PROCESSES!!`n"+
"Media will be copied to:`n"+$EDMAuto_Path
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tUnable to locate setup.exe - Begin Media Copy.`r`n")
#Execute the function to get the media copied local...
GetMedia
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tMedia copy complete.`r`n")
}
Else
{
#There are checks in here to validate certain directories have up to date info - but the main copy won't happen since
#it's been found in the check....
GetMedia
}
#############
#STEP 1 END
#############
<#
####################
STEP 2 BEGIN
##############################################################
Gather all the required information to run the SQL Server installation. This will produce
the $Config_INI variable that will be created and placed in the file:
D:\SQLAdmin\ConfigurationFile\ConfigurationFile.ini
##############################################################
#>
#IntroForm fuction is questioning if this is a named instance install. If it is, the value is set to $true and passed to
#the MainForm
#The MainForm function is run, and gather the rest of the information from the installer. When the installer "oks" the form,
#the information is passed into another function called: Compile_INI This function detects if any questions were left blank,
# and will then populate the variable $Config_INI.
#The bottem line is, Step one creates the $Config_INI, and passes along each config item as a varible.
#lets figure out if there are instances already installed first.
$instances = GetPrevInst
If ($instances)
{
$instanceArray=$instances.split(",")
#ok there are instances already installed - let's do a quick check to see if one of these
#instances = MSSQLSERVER - which means, a default instance has already been installed.
Foreach($Instance in $instanceArray)
{
if ($Instance -eq "MSSQLSERVER"){$default=$true}
}
}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tLaunching installation forms for required install data.`r`n")
#Let's call the intro form - if there is no default instance.
If ($default)
#if there is a default instance already installed - pass $true to Mainform, that tells it to ask for a Named instance install
{$Config_INI = MainForm ($default)}
Else
#if there is no default instance installed, then, let's ask the installer what they want to install, this decision will get passed to the main form.
{$Config_INI = MainForm (IntroForm)}
If (!$Config_INI)
{
Log-Message -Write $True -Msg ("$(Get-Date -format 'u')`tData Collection forms returned no data - Error - suspect installer killed the form. EXITING SCRIPT`r`n")
exit
}
########################
#STEP 2 END
########################
########################
#STEP 3 BEGIN
########################
<#
Here's our list of config variables we have at this point:
$InstanceName
$SrvAcctName
$SvcAcctPW
$AgtAcctName
$AgtAcctPW
$SSISAcctPW
$SSISAcctName
$FTAcctName
$FTAcctPW
$PrivGrp
$SAPW
$Config_INI -- the one we're going to use to create the ini file...
$SetupEXE -
#Base Admin Path
#Set-Variable -Name SQLAdmin_Path -Value "D:\SQLAdmin\" -Scope Script
#install media location:
#Set-Variable -Name SS_Setup_Folder -Value "SQLServer2012EE\" -Scope Script
#config file path:
#Set-Variable -Name Config_Folder -Value "ConfigurationFile\" -Scope Script
#>
#Let's create the config file -
#Create the folder if it doesn't exist:
$Config_Path = $SQLAdmin_Path+"\"+$Config_Folder
If (!(Test-Path $Config_Path))
{ $newfolder = $SQLAdmin_Path + "\" + $Config_Folder
# we already know the sqladmin folder exists, otherwise step one would have failed. so, just the config folder doesn't exist.
New-Item -Path $newfolder -ItemType directory | Out-Null
}
#If we're at this point, and the validation checks done in the configini function failed, we need to
#make sure they didn't just X out of the form after going back to the main form...
#it's a loophole found when passing between forms... if it's false, kill this script.. don't log a message.
If (!$VALIDATION_CHECK){Exit}
#We are ready to create the config file - but, before we do, let's just ask the installer if they are sure they want to continue with all the information we've gathered
#this function will decide if the script kills or not...
ConfirmInstall
$ConfigFile = $Config_Path+"ConfigurationFile.ini"
#Let's create the config file used for THIS install:
$Config_INI | Out-File -Filepath $ConfigFile -Force
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$ConfigFile CREATED...`r`n")
########################
#STEP 3 END
########################
########################
#STEP 4 BEGIN
########################
<#
If we're at step 4, that means we have our config file created and waiting to be used with a silent sql server install...
We're going to launch the install with a start-job commandlet. while it runs, the powershell script will go to sleep
and check it's progress until it completes. Once complete, we'll more on to step 5.
#>
#this job runs in the background... See function for more details...
$now = Get-Date | Out-String
#JobKickOff
$now
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t*BEGIN INSTALL OF INSTANCE: $InstanceName`r`n")
#$SetupFolder = $SQLAdmin_Path+$SS_Setup_Folder
#cd $InstallMedia_Path;.\setup.exe /configurationfile=$ConfigFile /INDICATEPROGRESS /q
cd $InstallMedia_Path;.\setup.exe /configurationfile=$ConfigFile /INDICATEPROGRESS /qs
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t***END INSTALL OF INSTANCE: $InstanceName`r`n")
#$ScriptBlock = {param($SetupFolder_, $ConfigFile_) cd $SetupFolder_;.\setup.exe /configurationfile=$ConfigFile_ /q `
# /INDICATEPROGRESS}
#$InstallStatus = Col-Jobs
########################
#STEP 4 END
########################
########################
#STEP 5 BEGIN
########################
#Clean Up - Remove Config file because it contains passwords
#$InstallStatus
#delete the config file
Remove-Item $ConfigFile -Force
Write-Host "$Configfile -- Has been REMOVED`n`n"
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$ConfigFile REMOVED...`r`n")
########################
#STEP 5 END
########################
########################
#STEP 6 BEGIN - POST INSTALL STEPS
########################
<#
IF there are no errors after the install, we're going to do the following post install items:
1.) Update the listening port to a port number between 11000 and 11999 - depending on what's already in use.
2.) Update the firewall to allow newly added port, ssis, and browser
The silent install passes a error code 0 even if it fails. To determine if the install worked, let's check
the registery for the new instance name. If it exists, then it work. If not, we'll throw an error.
We're going to use the function serverping to see if the instance exists...
#>
#SQLSERVER INSTANCE NAME TO CONNECT TO:
If ($instancename -eq "MSSQLSERVER")
{
Set-Variable -Name SQLInstance -Value $hostname -Scope Script
}
ELSE
{
Set-Variable -Name SQLInstance -Value "$hostname\$instancename" -Scope Script
}
If (!(SQLServicePing))
{
$Error
#An actual error may not have been detected - let's let the installer know that something happened because the actual instance doesn't exist.
$message = "!!!ERROR - NEW INSTANCE DOESN'T EXIST!!!`n`n"+
"Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tThe service for $InstanceName is not detected, or is not running. Either the installation errored or was stopped short of completion.`r`n"`
+ "`t`t`tCheck the bootstrap logs under C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log on $hostname`r`n`t`t`tEXITING SCRIPT.`r`n`r`n$Error")
Exit
}
Else
{
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe service for $InstanceName is detected. Begin Post Installation Processes...`r`n")
}
#If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instancename"))
#{
# #An actual error may not have been detected - let's let the installer know that something happened because the actual instance doesn't exist.
# $message = "!!!ERROR - NEW INSTANCE DOESN'T EXIST!!!`n`n"+
# "Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
# [Windows.Forms.MessageBox]::Show($message, `
# $Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
#
# Exit
#}
#Check the error status - if the install went without error, we'll continue on.
If (!$Error)
{
#We're going to check the port number and give it a NON dynamic port number > 11000
#Let's check all the port numbers of any SQL Instance. Make this newly installed instance 1 greater than the existing largest.
Write-Host "Install Success"
#lets do our first post install change - update the port this newly installed sql server is using.
$TCP_Port = SetPort
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tListening Port for $instancename has been updated to $TCP_Port.`r`n")
#FIREWALL UPDATE:
$newRuleName = "SQLServerEng_$instancename"
netsh advfirewall firewall add rule name = $newRuleName dir = in protocol = tcp action = allow localport = $TCP_Port remoteip = ANY profile = ANY
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tFireWall Rule added to allow anything to connect to Port $TCP_Port`r`n")
#if the port number is 11001, this means it's the first install of sql server for this program to install - set the next 2 only once...
If([int]$TCP_Port -eq 11001)
{
netsh advfirewall firewall add rule name = SQLServerSSIS dir = in protocol = tcp action = allow localport = 135 remoteip = ANY profile = ANY
netsh advfirewall firewall add rule name = SQLServerBrowser dir = in protocol = UDP action = allow localport = 1434 remoteip = ANY profile = ANY
}
#Let's restart the new instance - make sure the new port assignment takes effect.
If(RestartSQLServices){Write-Host "$instancename has been restarted - new port assignment complete."}
Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`t$instancename has been restarted - new port assignment complete.`r`n")
}
Else
{
#There was an error detected - let's let the installer know that, and also let them know the following information was not configured due to the error detected.
$message = "!!!INSTALL ERROR DETECTED!!!`n`n"+
"Check the bootstrap log for more details:`n`nC:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log"
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`t!!!ERROR DETECTED!!!`r`n"`
+ "`t`t`tCheck the bootstrap logs under C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Log on $hostname`r`n`t`t`tEXITING SCRIPT - See Error Details Below...`r`n`r`n$Error")
Exit
}
########################
#STEP 6 END
########################
########################
#STEP 7 BEGIN
########################
#On a FRESH install of SQL SErver - sql server pathes are not yet known in the path, therefore we must give the entire path of the sqlcmd.exe executable.
#"$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd.exe"
#in the command for sqlcmd.exe, we're doing a "cd" first....
#CREATE alternate sa account:
$SQL_AltSA_Create = "CREATE LOGIN ["+$SA_AltName+"] WITH PASSWORD=N'"+$SAPW+"', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON;`n" + `
"ALTER SERVER ROLE [sysadmin] ADD MEMBER ["+$SA_AltName+"];"
#DISABLE SA
$SQL_DisableSA = "ALTER LOGIN [sa] DISABLE;`n" + `
"select [name],case is_disabled when 1 then 'DISABLED' when 0 then 'ENABLED' END AccountStatus from master.sys.sql_logins where [name] in ('sa','"+$SA_AltName+"');"
##SQLSERVER INSTANCE NAME TO CONNECT TO:
#If ($instancename -eq "MSSQLSERVER")
#{
# $SQLInstance = $hostname
#}
#ELSE
#{
# $SQLInstance = "$hostname\$instancename"
#}
If (Test-Path -Path "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn")
{
#CONNECT AND CREATE
cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U sa -P $SAPW -Q "$SQL_AltSA_Create;"
If(!$error){Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe replacment SA account has been created.`r`n")}
#CONNECT AND DISABLE
cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U $SA_AltName -P $SAPW -Q "$SQL_DisableSA;"
If(!$error){Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tThe SA account has been Disabled.`r`n")}
#INSTALL EAM ACCESS OBJECTS - deploy_eam_allver.sql
#THIS SHOULD HAVE BEEN COPIED DURING THE MAIN COPY PROCESS: $EDMAuto_Path\Scripts\deploy_eam_allver.sql
####
# As of 08/16/2013 the EAM objects are no longer being included in the install package
####
#$EAM_DEPLOY_SQL = "$EDMAuto_Path\Scripts\deploy_eam_allver.sql"
#$EAM_OUT = "$EDMAuto_Path\Logs\eam_out.txt"
#If(Test-Path $EAM_DEPLOY_SQL)
#{
# cd "$Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"; .\sqlcmd.exe -S $SQLInstance -U $SA_AltName -P $SAPW -i "`"$EAM_DEPLOY_SQL`"" -o $EAM_OUT
#}
#If (Test-Path $EAM_OUT)
#{
# $eamOut = Get-Content -Path $EAM_OUT
# Remove-Item -Path $EAM_OUT
#
# If ($eamOut -match "error" -or $eamOut -match "Msg")
# {
# $EAM_Error = $true
# Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tEAM Deployment was attempted, and may have failed - review the following output:`r`n`r`n$eamOut")
# }
# Else
# {
# Log-Message -Write $false -Msg ("$(Get-Date -format 'u')`tEAM Deployment was SUCCESS - EAM output:`r`n`r`n$eamOut")
# }
#
#
#}
}
Else
{
$PathCheck = "PATH NOT FOUND!!! $Install_Drive\Program Files\Microsoft SQL Server\110\Tools\Binn"
}
# Removing EAM error check per version 1.1.2
#If ($Error -or $PathCheck -or $EAM_Error -or !$eamOut)
If ($Error -or $PathCheck)
{
$message = "!!!ERROR DETECTED!!!`n`n"+
"Review the PowerShell console for any error messages the may have occurred.`n`n"+
"Install Log File Can Be Found: $EDMAuto_Path\Logs\`n`n"+
"Send questions or concerns to the email address: EDM_DAN_SQL@wellsfargo.com "
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`tError Detected - Review error details.. `r`n"`
+"`t`t`tThis error comes when process was connecting to newly installed instance to disable SA and create SA replacement...`r`n`r`n$Error$PathCheck`r`n`r`nEXITING SCRIPT`r`n")
}
Else
{
$message = "!!!INSTALL SUCCESS!!!`n`n"+
"Post Install Steps include the following:`n"+
"SQL Server Port Changed to Static Port # $TCP_Port`n"+
"Fire Wall updated with new port number.`n"+
"SA Account has been disabled.`n"+
"$SA_AltName has been created.`n"+
#"EAM Objects have been deployed.`n`n"+ #EAM Objects are no longer part of this install package as of version 1.1.2
"Install Log File Can Be Found:`n`t$EDMAuto_Path\Logs\`n`n"+
"Please verify your install of $SQLInstance`n`n"
Log-Message -Write $true -Msg ("$(Get-Date -format 'u')`t$message")
[Windows.Forms.MessageBox]::Show($message, `
$Form_Name, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information) | Out-Null
}
exit
########################
#STEP 7 END
########################
Comments
Post a Comment