Skip to content

Instantly share code, notes, and snippets.

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

Timothy Addison taddison

👻
(⊙_⊙;)
View GitHub Profile
@taddison
taddison / partition_stats_loop.sql
Created November 29, 2016 10:20
Pull dm_db_partition_stats from DB with many partitions
set nocount on;
drop table if exists #objects;
drop table if exists #ddps;
select object_id, identity(int,1,1) as id
into #objects
from sys.objects as o
where o.type = 'U' /* USER_TABLE */
and o.is_ms_shipped = 0;
@taddison
taddison / TelemetryClientExtensions.cs
Created February 23, 2017 21:11
Extension method to time and track a dependency
using Microsoft.ApplicationInsights;
using System;
public static class TelemetryClientExtensions
{
public static TResult TrackDependencyTiming<TResult>(this TelemetryClient client, string dependencyName, string commandName, Func<TResult> function)
{
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();
var success = true;
@taddison
taddison / single_server_payload.json
Created August 6, 2017 08:27
Sample OMS alert search result payload - single server
{
"incidentname": "Test",
"IncludeSearchResults": true,
"SearchResults": {
"id": "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/oi-default-east-us/providers/Microsoft.OperationalInsights/workspaces/...|2017-08-0607-46-30Z",
"__metadata": {
"top": 2147483647,
"RequestId": "4a37b79a-a875-40ad-9cbc-9d3dfcfa4df7|2017-08-0607-46-30Z",
"Status": "Successful",
"NumberOfDocuments": 0,
@taddison
taddison / ssrs_failed_subscriptions.sql
Last active August 23, 2017 08:59
ReportServer - failed subscriptions
use ReportServer
go
drop table if exists #failedSubs
select c.ItemID
,u.UserName as SubscriptionOwner
,s.Description as SubscriptionDescription
,s.LastStatus
,s.SubscriptionID
,c.Name as ReportName
@taddison
taddison / removetag.ps1
Created September 4, 2017 11:42
Remove a tag (AzureRM)
############
# Remove a tag
$tagToRemove = "SupportContact"
Write-Host [Start] Tag utilisation: $tagToRemove
Get-AzureRmTag -Name $tagToRemove
## Remove from resources
$resources = Find-AzureRmResource -Tag @{$tagToRemove=$null}
foreach($resource in $resources)
{
@taddison
taddison / record_wait_stats.sql
Created October 30, 2017 10:20
Record wait stats and schedule with tsqlscheduler
if not exists (select 1 from sys.schemas as s where s.name = 'logs')
exec('create schema logs authorization dbo');
go
if not exists(select 1 from sys.schemas as s where s.name = 'logging')
exec('create schema logging authorization dbo');
go
create table logs.InstanceWaitStats
(
CollectionTime datetime2(0) not null
,WaitType nvarchar(60) not null
Import-Module C:\src\tsqlScheduler\src\Modules\tsqlScheduler -Verbose -Force
$pathToTaskToDelete = "C:\src\DBTasks\AGName\AGName-DBName-JobToDelete.json"
$ag = "AGName"
$db = "SchedulerDBName"
$domain = "foo.corp"
$serverInstance = "$ag.$domain"
$task = (Get-Content -Raw $pathToTaskToDelete | ConvertFrom-Json)
@taddison
taddison / moveSSRSReportOwners.ps1
Created January 9, 2018 16:37
Move SSRS owners
$leaver = "foo\tim.isleaving"
$newOwner = "foo\tim.isreplaced"
$rs2010 = New-WebServiceProxy -Uri "http://gogoreports/ReportServer/ReportService2010.asmx" -Namespace SSRS.ReportingService2010 -UseDefaultCredential ;
$allSubscriptions = $rs2010.ListSubscriptions("/")
$subsToMove = ($allSubscriptions | Where-Object { $_.Owner -like $leaver })
$subsToMove | Select-Object Path, Owner, Report | Format-Table
$subsToMove | ForEach-Object { $rs2010.ChangeSubscriptionOwner($_.SubscriptionID, $newOwner) }
# has a -whatif
$cred = get-credential
$servers = @("server1", "server2")
foreach($server in $servers)
{
Invoke-Command -ComputerName $server -Credential $cred -ScriptBlock { get-msmqqueue | where-object { $_.QueueName -like "*somequeuewildcard*" } | Clear-MsmqQueue -WhatIf }
}
@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.*