Skip to content

Instantly share code, notes, and snippets.

View schwartzmx's full-sized avatar
👓

Phil Schwartz schwartzmx

👓
View GitHub Profile
@schwartzmx
schwartzmx / BlockUserInput.ps1
Created January 13, 2017 06:07
Block user input. Mouse, and keyboard are disabled for the duration.
$code = @"
[DllImport("user32.dll")]
public static extern bool BlockInput(bool fBlockIt);
"@
$userInput = Add-Type -MemberDefinition $code -Name UserInput -Namespace UserInput -PassThru
Function Disable-UserInput {
param([int]$Seconds=5)
$userInput::BlockInput($true) | out-null
@schwartzmx
schwartzmx / redshift_revoke_drop_user.sql
Last active May 26, 2023 17:14
Various queries for finding and generating statements to revoke all privileges and drop a user from AWS Redshift.
-- check if they own any databases
select d.datname as name,
pg_catalog.pg_get_userbyid(d.datdba) as db_owner,
'alter database '+d.datname+' owner to <user>;' as chg_owner
from pg_catalog.pg_database d
where pg_catalog.pg_get_userbyid(d.datdba) = '<user>'
order by d.datname;
-- check if they own any schemas
select nspname, usename, 'alter schema '+nspname+' owner to <user>;' as chg_owner
@schwartzmx
schwartzmx / keybase.md
Created September 15, 2016 16:04
keybase.md

Keybase proof

I hereby claim:

  • I am schwartzmx on github.
  • I am schwartzmx (https://keybase.io/schwartzmx) on keybase.
  • I have a public key whose fingerprint is 5FD3 7845 FB08 46F6 6D0F CC00 3B5C B261 00D2 E70F

To claim this, I am signing this object:

@schwartzmx
schwartzmx / SQL_CheckWFClusterLogs.ps1
Last active September 19, 2016 16:42
Intended only to be run as a scheduled job on a SQL Server. This should be scheduled every $LogTimeSpanMinutes as a SQL Agent job. This grabs the events logs and emails on Error level logs being found and shoots an email with the contents of the errors.
$LogTimeSpanMinutes = 10
$AfterDate = (Get-Date).AddMinutes(-$LogTimeSpanMinutes)
$SQLMailProfile = "DoNotReplyNotification"
$recipients = "email@gmail.com"
$subject = "Failover Cluster ERRORS"
$body = "<!DOCTYPE html><html><head></head><br><body> {0} </body></html>"
$LocalServer = hostname
Function DBA-SendMail {
param(
@schwartzmx
schwartzmx / SQLServer_SSIS-Transfer.ps1
Last active August 12, 2016 19:16
Transfer SSIS Folders and Projects from a source server to a destination server.
<#
Transfer SSIS Folders and Projects from a source server to a destination server.
Mostly taken from http://widba.blogspot.com/2013/02/moving-SSIS-projects-in-sql-server-2012.html with some added functionality for copying ALL SSIS packages and folders to the destination
Note this does have to use SSPI Integrated Security for copying from the Source to Dest
Author: Phil Schwartz
#>
@schwartzmx
schwartzmx / SQLServer_SettingsTransfer.ps1
Last active August 12, 2016 22:09
SQL Server jobs, linked servers, etc.. transfer from a source server to targets using SMO
<#
Note: Before running, make sure you have any relevant Credentials copied over and maintenance plans, or referenced objects could cause failures in the script.
Author: Phil
#>
$Source = "" # ex. "Source-SQL"
$SQLUser = "" # user
$SQLPassword = "" # password
$Targets = "" # ex. "Target-SQL"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
@schwartzmx
schwartzmx / olympic_medals_scraper.py
Last active January 19, 2017 15:05
Simple script to scrape the default grid Olympic medals table on NBC's site and dump the result as JSON
from bs4 import BeautifulSoup
import requests as r
from json import dumps
class Country:
def __init__(self, country, place, gold, silver, bronze, total_medals):
self.country = country
self.place = place
self.gold = gold
self.silver = silver
@schwartzmx
schwartzmx / SQLServerKB-RSSFeed.ps1
Created June 23, 2016 01:58
A simple PowerShell script to read the RSS feed for SQL Server KB support updates
<#
Author: Phil Schwartz
Description: A simple script to read the RSS feed for SQL Server KB support updates
- Allows stepping through the feed and opening in browser, if specified
#>
[xml]$xmldoc= Invoke-WebRequest 'https://support.microsoft.com/en-us/rss?rssid=1044'
$feed = $xmldoc.rss.channel
$lid = 0
# Quick abstraction test
$d = (Get-Date)
$frequency = "Weekly"
$query = "exec prc_ReportXYZ {0}, {1};"
switch ($frequency) {
"Weekly" {
$beginDate = $d.AddDays(-$d.DayOfWeek).ToString('MM/dd/yy')
$endDate = (Get-Date $beginDate).AddDays(7).ToString('MM/dd/yy')
}
"Monthly" {
@schwartzmx
schwartzmx / prc_Magic8Ball.sql
Last active February 12, 2016 05:14
T-SQL Magic8Ball
create procedure [prc_Magic8Ball]
(
@question varchar(100)
)
-- Author: Phil
-- Example: exec prc_Magic8Ball 'Will I make it into the office on time today?';
as
begin
set nocount on;
declare @phrase as table (name varchar(50));