Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
# https://4bes.nl/2021/09/19/update-all-powershell-modules-on-a-system/
<#
TIM C: Changes:
- Added scope parameter so scope could be controlled
- altered code to always check for old versions, as this script may not have done the install, but it can still remove old versions
- changed contains and othercomparison syntax to be case insensitive
- altered logic around when the module is not found in the gallery to make the verbose output clearer
- added version parses around the version compares so string comparisons do not screw up the comparison
- added admin check when using AllUsers
@tcartwright
tcartwright / ScriptDatabaseFiles.md
Last active January 3, 2023 16:17
POWERSHELL: Script database into files
@tcartwright
tcartwright / AAA-MY-Red-Gate-Snippets.md
Last active December 14, 2024 19:01
My Red Gate Snippets

These are my Red Gate Snippets for use with SQL Prompt.

How to use:

  • The powershell file "PushSnippets.ps1" is used to update them.
  • It can be modified so as to push your own snippets once you create a GIST for them.
  • Read the instructions detailed in the powershell file
@tcartwright
tcartwright / SafeShrinkDatabase.md
Last active January 3, 2023 16:18
POWERSHELL: Safely shrink database without fragmenting indexes
@matthew-n
matthew-n / ErrorHandler.sql
Last active March 21, 2024 01:28
SQL Server: TSQL Callstack Emulation
IF OBJECT_ID('dbo.ErrorHandler') IS NULL BEGIN
EXEC ('CREATE PROCEDURE dbo.ErrorHandler AS BEGIN SELECT 1; END;');
END
GO
--our error handling procedure
ALTER PROCEDURE dbo.ErrorHandler @procName NVARCHAR(128), @ErrorMessage NVARCHAR(4000) OUTPUT, @ErrorSeverity INT OUTPUT, @ErrorState INT OUTPUT
AS
BEGIN
/* declare sessions keys that are safe for multiple sessions on a single connection */
@tcartwright
tcartwright / SQL Server Stored Procedures StackTrace - 2016.sql
Last active January 21, 2022 15:49
SQL Server Stored Procedures StackTrace - 2016
/*
Authors: Matthew Naul, Tim Cartwright
Purpose: to build a stack trace so that nested stored proces can be followed in the case of an exception.
*/
USE tempdb -- change this to the db of your choice. or put it master and make it a system stored proc
GO
IF OBJECT_ID('dbo.ErrorHandler') IS NULL BEGIN
EXEC ('CREATE PROCEDURE dbo.ErrorHandler AS BEGIN SELECT 1; END;');
@tcartwright
tcartwright / InefficientQueries.sql
Last active August 30, 2023 20:08
SQL SERVER: Find Inefficient Queries
/*
Author: Tim Cartwright
1) Leave the @dbname variable empty or null for all databases
2) Changed the @dbname variable to a specific variable to only get the queries for that database.
RETURNS: The queries with the highest cost, and longest working time with the worst offenders being at the top of the list.
*/
DECLARE @dbname sysname = '', -- '',