Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / VisualStudioPowershell.md
Last active January 3, 2023 16:49
POWERSHELL: Turn any instance of powershell into an instance that supports Visual Studio command prompt
@tcartwright
tcartwright / ServerSettingsCompare.md
Last active January 3, 2023 16:22
SQL Server: Lets you generate a comparison report of the server settings of 2 or more servers
@tcartwright
tcartwright / GetBackupInformation.sql
Last active March 4, 2021 15:19
SQL SERVER: Backups info (Can be visualized in OUTLOOK)
/*
Tim C: This query can be used as a normal query, or it can also be used to import into an OUTLOOK calendar so
you can visualize your backups. Similar to https://dbatools.io/timeline/
RECOMMENDATIONS:
1) You should import into a CUSTOM blank excel calendar
2) You should not import TLOG backups, as that will utterly bloat the calendar
******************************************************************************************
TO CREATE A NEW CALENDAR:
@tcartwright
tcartwright / ExtractMissingIndexesFromPlan.ps1
Last active January 25, 2021 15:03
SQL SERVER ExtractMissingIndexesFromPlan
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $path
)
Clear-Host
[xml]$plan = Get-Content -Path ($path.TrimStart('"').TrimEnd('"'))
@tcartwright
tcartwright / CombinePlans.ps1
Created January 21, 2021 18:19
SQL SERVER: Combine Plans into One
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $ServerInstance,
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $planHandle
)
<#
@tcartwright
tcartwright / GenerateOlaBackupScripts.sql
Last active December 1, 2020 17:39
Generate Ola Backup Scripts
/*
TIM C: Generates 4 backup job scripts for ola hallengren backups. Splits the databases as evenly by size as it can. The options for the job can be changed below.
Alternative to using "DatabasesInParallel = true" with "DatabaseOrder = DATABASE_NAME_DESC" https://ola.hallengren.com/sql-server-backup.html
Allows for manual editing of database order and job distribution. The output of each script can be set up as a seperate job.
TO DO: automate - job creation and job update.
*/
-- CHANGE ME
@tcartwright
tcartwright / GenerateMerge.psm1
Last active September 17, 2021 22:28
POWERSHELL: a script that can generate a merge statement from a query
function GetByteString([Byte[]]$bytes) {
#TIM C: I am not sure this is the proper way to do this, but it seems to work in all the test cases I throw at it.
$byteStr = [System.BitConverter]::ToString($bytes).Replace("-", "")
return "0x$byteStr";
}
function GetColumnValueFormat ([string] $DataType, [string] $ColumnName, [switch]$ReplaceDollarSignsInValues = $false) {
#TIM C: constructing the proper format of these is a PITA. Its best to copy the result into a another powershell window to check the syntax
$value = "`$(switch(`$reader.IsDBNull(`$reader.GetOrdinal(`"$ColumnName`"))){`$true{`"NULL`"}`$false{%%FALSE_PART%%}})";
#`$reader.GetValue(`$reader.GetOrdinal(`"$ColumnName`"))
@tcartwright
tcartwright / Telnet.psm1
Last active March 24, 2024 16:38
Windows: Powershell telnet client. Can run interactively or take an array of commands
<#
.Synopsis
Tests the connectivity between two computers on a TCP Port
.Description
The Telnet command tests the connectivity between two computers on a TCP Port. By running this command, you can determine if specific service is running on Server.
.Parameter <ComputerName>
This is a required parameter where you need to specify a computer name which can be localhost or a remote computer
@tcartwright
tcartwright / ContextInfo.sql
Created May 21, 2020 14:08
SQL Server: Context Info
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID('dbo.SetContextInfo') IS NOT NULL BEGIN
DROP PROCEDURE [dbo].[SetContextInfo]
END
GO
/*=============================================