Skip to content

Instantly share code, notes, and snippets.

<#
.SYNOPSIS
Applies SQL group membership (unless exists) on availablitiy group nodes using windows login, from a definition file.
.DESCRIPTION
Applies SQL group membership (unless exists) on availablitiy group nodes using windows logins and groups, from a definition file.
Based on a role definition file, SQL snippets are generated and then executed.
Removes any login/dbuser mapping that are in conflict with the securityDefinitionFile specification.
.PARAMETER masterEndpoints
List of FQDN[,<port>] of SQL nodes participating in the availability group
.PARAMETER instanceEndpoint
@Tewr
Tewr / ComponentModelExtensions.cs
Last active July 6, 2016 14:24
Helper for classes decorated with DefaultValueAttribute
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
namespace Extensions
{
public static class ComponentModelExtensions
{
public static TProperty GetPropertyValueOrDefault<TSource, TProperty>(
@Tewr
Tewr / BuildTimeInfo.tt
Created October 5, 2015 07:52
BuildTimeInfo Setup
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ output extension=".cs" #>
<#
string datePattern = "fffssmmHHddMMyyyy";
string buildTime = DateTime.Now.ToString(datePattern);
string humanReadableBuildTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
#>using System;
using System.Globalization;
@Tewr
Tewr / Windows Task Scheduler service restart export.xml
Created February 9, 2015 15:21
Batch, log and task scheduler export for restarting a windows service that has gone down for whatever reason (on event 0 + random checks every 30 minutes)
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2014-02-20T16:20:55.1120404</Date>
<Author>[account]</Author>
<Description>Attempts to start SERVICE_NAME. Logs the attempt to start it to a log file if the service was not started.</Description>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
@Tewr
Tewr / StreamExtensions.cs
Created November 7, 2014 05:21
Stream CopyTo with bytecount
namespace Extensions {
public static class StreamExtensions
{
/// <summary>
/// Implementation of <see cref="Stream.CopyTo(System.IO.Stream)"/> with progress reporting
/// </summary>
/// <param name="fromStream"></param>
/// <param name="destination"></param>
/// <param name="bufferSize"></param>
/// <param name="progressInfo"></param>