Post Installation



## This is a PS script to Perform the Post-Installation steps on 2012\14
## Developer


##
##


$ErrorActionPreference = "SilentlyContinue"
#$M = read-host -prompt "Please enter the machine name: "
$I = read-host -prompt "Please enter the full instance name eg., clwtd4000\SQL2008INS3: "
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&yes",""
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&no",""
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)

$caption = "Scom install"
$message = "is this server prod?"
$result = $Host.UI.PromptForChoice($caption,$message,$choices,0)

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null

$login = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login  -ArgumentList $I, 'ad-ent\prv_edm_fa_srv_sqlserviceaccounts'
$login.LoginType = 'WindowsLogin'
$login.AddToRole('sysadmin')
$login.Alter()

$login = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login  -ArgumentList $I, 'AD-ENT\PRV_CAO_AS_SRV_SQLSECURITYADMINS'
$login.LoginType = 'WindowsLogin'
$login.AddToRole('sysadmin')
$login.Alter()

$login = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login  -ArgumentList $I, 'AD-ENT\SCAO_TIM_SQL'
$login.LoginType = 'WindowsLogin'
$login.AddToRole('sysadmin')
$login.Alter()

#givining the sql instance details to configure min and max values

$cn = new-object System.Data.SqlClient.SqlConnection "server=$I;database=master;Integrated Security=sspi"
$cn.Open()
$sql = $cn.CreateCommand()
$I
$sql.CommandText = "EXEC msdb.dbo.sp_set_sqlagent_properties @jobhistory_max_rows=999999,@jobhistory_max_rows_per_job=99999;"

$rdr = $sql.ExecuteNonQuery();
$cn.close()

$srv = new-object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $I
$database =new-object Microsoft.SqlServer.Management.Smo.database
$database=$srv.Databases.Item("master")
foreach ($db in $database)
{
    $svr
$db.name
    $fg = $db.FileGroups
foreach ($group in $fg)
    {
$group.Name
foreach ($file in $group.Files)
        {
$file.filename
            $file.size=102400
            $file.Growth = 102400
       $file.GrowthType = 'KB'
$file.MaxSize = -1  # Set to unlimited growth or replace with some value in KB
$file.Alter()
            #write-host "changed value for master database"
            $file.size
        }
     }
     foreach ($log in $db.LogFiles)
     {
$log.filename
        $log.size=102400
$log.Growth = 102400
$log.GrowthType = 'kb'
        $log.MaxSize = -1
        $log.Alter()
        $log.size
     
}
}


$database=$srv.Databases.Item("msdb")
foreach ($db in $database)
 {
$db.name
    $fg = $db.FileGroups
foreach ($group in $fg)
    {
$group.Name
foreach ($file in $group.Files)
        {
$file.filename
            $file.size=102400
            $file.Growth = 102400
       $file.GrowthType = 'KB'
$file.MaxSize = -1  # Set to unlimited growth or replace with some value in KB
            $file.Alter()
            #write-host "changed value for msdb database"
            $file.size
         }
     }
     foreach ($log in $db.LogFiles)
     {
$log.filename
        $log.size=102400
$log.Growth = 102400
$log.GrowthType = 'kb'
        $log.MaxSize = -1
        $log.Alter()
        $log.size
     
}
}


$database=$srv.Databases.Item("model")
foreach ($db in $database)
 {
$db.name
    $fg = $db.FileGroups
foreach ($group in $fg)
    {
$group.Name
foreach ($file in $group.Files)
        {
$file.filename
            $file.size=102400
            $file.Growth = 102400
       $file.GrowthType = 'KB'
$file.MaxSize = -1  # Set to unlimited growth or replace with some value in KB
            $file.Alter()
            $file.size
         }
     }
     foreach ($log in $db.LogFiles)
     {
$log.filename
        $log.size=102400
$log.Growth = 102400
$log.GrowthType = 'kb'
        $log.MaxSize = -1
        $log.Alter()
        $log.size
     
}
}


     
     
#changing backup compression default;creating polkj11 with sysadmin;sa disable;revokeconnect from guest in modeldb
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server = $I; Integrated Security = True; Initial Catalog='master'"
$sqlConnection.Open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "sp_configure 'backup compression default','1';reconfigure with override"
$SqlCmd.Connection = $SqlConnection
$postinstallation = $SqlCmd.ExecuteScalar()
$SqlConnection.Close()


write-host "done with Enable backup compression and changing the file sizes of master,model and msdb"



Comments

Popular posts from this blog

Netezza Commands

MS SQL Server Tips

MongoDB Version Upgrade 3.4 to 3.6