Skip to content

Instantly share code, notes, and snippets.

View taddison's full-sized avatar
👻
(⊙_⊙;)

Timothy Addison taddison

👻
(⊙_⊙;)
View GitHub Profile
@taddison
taddison / appinsights-sql-check.cs
Created December 20, 2018 21:03
appinsights sql check
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DependencyCollector;
using Microsoft.ApplicationInsights.Extensibility;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@taddison
taddison / postToLogAnalytics.ps1
Created August 26, 2018 23:40
Post an object to Log Analytics with PowerShell
# Adapted from https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api
Function Get-LogAnalyticsSignature {
[cmdletbinding()]
Param (
$customerId,
$sharedKey,
$date,
$contentLength,
$method,
$contentType,
@taddison
taddison / avroreader.cs
Created August 17, 2018 12:58
Read Avro EventHubs capture file (credit @Kadajski)
using Microsoft.Hadoop.Avro.Container;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace AvroReader
{
public class AvroEventData
@taddison
taddison / RestartServiceUsingMemory.ps1
Created July 13, 2018 11:10
Restart a windows service using more memory than a given cutoff
#requires -RunAsAdministrator
$serviceName = "BITS"
$cutoffGB = 0.0001
$processId = (Get-WMIObject win32_service | where { $_.name -eq $serviceName}).ProcessID
$process = Get-Process -Id $processId
$workingSet = $process.WorkingSet64
$workingSetGB = $workingSet / 1GB
@taddison
taddison / find_describe_tag.ps1
Created July 5, 2018 21:35
Find the first tag value for a describe block in a pester test file
$text = Get-Content .\src\SQLChecks\Tests\Databases.tests.ps1
$ast = [Management.Automation.Language.Parser]::ParseInput($text, [ref]$null, [ref]$null)
$ast.FindAll({
param($t)
$t -is [System.Management.Automation.Language.CommandAst] -and
$t.CommandElements[0].Value -eq "Describe"
}, $true) | ForEach-Object {
$_.CommandElements[3].Value
}
@taddison
taddison / ConfigureDBMailWithSendGrid.sql
Created April 23, 2018 19:27
Configure DBMail with SendGrid
declare @mailFromDomain nvarchar(128) = N'@foo.com'
declare @username nvarchar(128) = 'apikey'
declare @password nvarchar(128) = 'SG.SECRETS';
declare @port int = 587;
declare @server nvarchar(128) = 'smtp.sendgrid.com'
declare @replyTo nvarchar(128) = 'donotreply' + @mailFromDomain;
declare @serverName nvarchar(128) = substring(@@servername,8,100);
declare @emailAddress nvarchar(128) = @serverName + @mailFromDomain;
declare @displayName nvarchar(128) = @serverName;
@taddison
taddison / removedbmailnondefault.sql
Last active April 24, 2018 08:37
Remove all non-default profiles + accounts from DBMail
declare @defaultProfileId int;
select @defaultProfileId = pp.profile_id
from dbo.sysmail_principalprofile as pp
where pp.principal_sid = 0x00 /* Guest */
and pp.is_default = 1
if @defaultProfileId is null
begin
;throw 50000, 'No default profile set', 1
return
@taddison
taddison / addappinsights.ps1
Created April 23, 2018 13:46
Add app insights perf counters
$cred = Get-Credential -UserName "foo\admin"
$servers = @("server1","server2")
foreach($server in $servers)
{
Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock {
Add-LocalGroupMember -Group "Performance Monitor Users" -Member "foo\service1"
Add-LocalGroupMember -Group "Performance Monitor Users" -Member "foo\service2"
}
}
@taddison
taddison / cleanupssrsjobs.sql
Created April 18, 2018 11:47
Clean up SSRS jobs from a server
use msdb
go
declare @id int = 0
select j.job_id, identity(int,1,1) as id
into #jobs
from dbo.sysjobs as j
join dbo.syscategories as c
on c.category_id = j.category_id
where c.name = 'Report Server'
@taddison
taddison / active_transactions.sql
Created February 13, 2018 14:06
Active transactions
select datediff(minute, dtdt.database_transaction_begin_time, getutcdate()) as TransactionDurationMinutes
,d.name as DatabaseName
,dtst.session_id
,dtdt.database_transaction_log_record_count
,cast(dtdt.database_transaction_log_bytes_used / 1024. / 1024. as decimal(17,2)) as LogUsedMB
,des.program_name
,des.host_name
,des.nt_user_name
,map.*
,dest.*