Skip to content

Instantly share code, notes, and snippets.

View paschott's full-sized avatar

Peter Schott paschott

View GitHub Profile
@paschott
paschott / InstallApps.ps1
Last active May 6, 2024 18:15
Use Chocolatey to install some common apsp for MS SQL work and related
#Note - will want to install "Chocolatey" first in order to use this file to install software.
# https://chocolatey.org/docs/installation
# Open a command prompt (cmd) and run the following:
# @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
# ..
# or open a PowerShell Admin prompt and run:
# Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# After Chocolatey is installed, open a PS prompt in Administrator mode,
--Adapted from http://www.chilledsql.com/welcome/tip_category_dateandtime/tip_detail_dateandtime_createmastercalendartable
--If this is an existing table, do not drop/recreate the table, just adjust dates and run the appropriate population script
--Adjust code to ignore dates already in the calendar table.
SET NOCOUNT ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET ARITHIGNORE ON
@paschott
paschott / calendar_table.sql
Last active March 25, 2024 14:29
Calendar Table and Population
/* Adapted from ChilledSql.com */
/* https://www.chilledsql.com/welcome/tip_category_dateandtime/tip_detail_dateandtime_createmastercalendartable */
/* Update the Start/End dates as appropriate for your needs */
/* This is done after all creates */
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT ON
SET ANSI_WARNINGS OFF
SET ARITHABORT OFF
@paschott
paschott / New-SQLServerCertificate.ps1
Created December 10, 2020 01:08
Passes a CSR to the Certificate Authority, downloads the certificate, passes it to the target server, then imports and sets it for SQL Server
#requires dbatools
$server = "servername"
$localCertPath = "C:\CertificateRequests"
$remoteCertPath = "C:\CertificateRequest\"
$adminuser = Import-Clixml C:\user.cred #stored credentials to access remote server
# Generate the CSR and download locally
$session = New-PSSession $server -Credential $adminuser
@paschott
paschott / Generate-CSR.ps1
Created November 24, 2020 22:38
PowerShell script to generate a Certificate Request for a server using certain criteria
#Create new Certificate Request for SQL Server security
# Should be made into a function at some point
# Needs to be able to handle Cluster names/IP addresses
#Set location of the server
$Location = "City"
$State = "State"
$OU = "OU"
$Company = "Organization"
@paschott
paschott / Generate_Spelling_Audio.py
Last active November 15, 2023 00:45
Text to Speech for creating a practice spelling bee audio file
# requires gtts
# requires pydub
# requires ffmpeg to be installed on the system
from gtts import gTTS
from pydub import AudioSegment
import os
def generate_word_audio(word, output_folder='audio'):
if not os.path.exists(output_folder):
@paschott
paschott / AzureSQLPermissions.sql
Last active September 26, 2023 16:15
Get Azure SQL Database Permissions
/* Get all db principals and their roles for Azure SQL */
SELECT
@@ServerName as ServerName,
DB_NAME() as DatabaseName,
pr.name AS PrincipalName,
pr.type_desc AS PrincipalType,
r.name AS RoleName,
dp.state_desc AS RoleState,
NULL as PermissionName,
NULL as PermissionState,
@paschott
paschott / Restore-InstallerFiles.ps1
Created July 18, 2023 14:50
This script was designed as a fix Windows "Installer" by restoring the missing Package(*.msi)/Patches(*.msp) files with the following steps: 1. Identifying the missing files. 2. Crawl the missing files from specified folder or other healthy machine.
<#
Code Type: Function
Description: Restore the missing Package(*.msi)/Patches(*.msp) files from another remote source (machine or folder).
Author: Ahmad Gad
Contact Email: ahmad.gad@jemmpress.com, ahmad.adel@jemmail.com
WebSite: http://ahmad.jempress.com
Created On: 21/09/2016
Updated On: 11/03/2017
Title: Restore-InstallerFiles
Minimum PowerShell Version: 2.0
@paschott
paschott / Disabling_Triggers.sql
Last active July 12, 2023 15:52
Disabling Triggers
CREATE TABLE TriggerStatus (
TriggerStatusID INT IDENTITY(1,1) NOT NULL,
TriggerName varchar(100) NOT NULL,
IsEnabled BIT NOT NULL CONSTRAINT DF_TriggerStatus_IsEnabled DEFAULT 1,
CONSTRAINT PK_TriggerStatus PRIMARY KEY CLUSTERED (TriggerStatusID)
)
GO
CREATE TABLE MyAuditTable (
MyAuditTableID INT NOT NULL IDENTITY(1,1),
@paschott
paschott / usp_PurgeSSISCatalogLogs.sql
Created October 28, 2020 18:32
Creates stored procedure to purge SSIS catalog in batches of rows from child to parent.
use SSISDB
GO
CREATE PROC dbo.usp_PurgeSSISCatalogLogs
@RowsToDelete int = 5000
AS
BEGIN --Proc
/*
Script name: Purge SSIS Catalog log tables
Author: Tim Mitchell (www.TimMitchell.net)