Skip to content

Instantly share code, notes, and snippets.

View josheinstein's full-sized avatar

Josh Einstein josheinstein

  • Einstein Technologies
  • USA
View GitHub Profile
@josheinstein
josheinstein / Test-Requirement.psm1
Created April 30, 2012 16:10
Test-Requirement - Would love to see something like this in PowerShell.
##############################################################################
#.SYNOPSIS
# Ensures that certain dependencies are available in the current environment.
#
#.DESCRIPTION
# Test-Requirement will throw an exception if the requirement is not met, or
# it will write a verbose message if the requirement succeeds. It is not
# intended to be used in a conditional statement, rather it is intended to be
# used at the top of your function as a declarative statement in a scope that
# will be aborted if an exception is thrown.
@josheinstein
josheinstein / Args.cs
Created April 30, 2012 16:21
Argument Validation Helper (C#)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
/// <summary>
/// Provides methods for checking method arguments for validity and throwing localizable exceptions for invalid
/// arguments or argument combinations.
@josheinstein
josheinstein / LINQ.psd1
Created April 30, 2012 16:29
LINQ-ish Cmdlets for PowerShell
@{
# MODULE
Description = 'LINQ for PowerShell'
ModuleVersion = '3.0'
GUID = '03BDA80F-0831-406E-B6AE-59E32D73F190'
# AUTHOR
Author = 'Josh Einstein'
CompanyName = 'Einstein Technologies'
@josheinstein
josheinstein / CollectionHelper.cs
Created May 1, 2012 21:16
Testing sets for equality (IEnumerable and IDictionary)
using System;
using System.Collections;
public static class CollectionHelper {
public static bool SetsEqual(IEnumerable set1, IEnumerable set2) {
var h1 = new Hashtable();
foreach ( var item in set1 ) {
h1[item] = true;
@josheinstein
josheinstein / PSObjectComparer.cs
Created May 1, 2012 21:17
IComparer for PSObjects in PowerShell
namespace Einstein.PowerShell
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
@josheinstein
josheinstein / Enable-AppearOffline.ps1
Created May 3, 2012 15:09
Enable "Appear Offline" in Microsoft Lync
$ErrorActionPreference = 'Stop'
try {
$LyncPolicyKey = 'HKLM:\Software\Policies\Microsoft\Communicator'
if (!(Test-Path $LyncPolicyKey)) {
New-Item $LyncPolicyKey
}
@josheinstein
josheinstein / DataSize.cs
Created May 18, 2012 16:15
DataSize Class (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
@josheinstein
josheinstein / SCoreShell.cs
Created May 21, 2012 15:28
SCoreShell - Windows Server Core PowerShell prompt at login with auto-logoff on exit
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace SCoreShell
{
/// <summary>
/// This application's sole purpose in life is to sit in for the default "shell" on a
@josheinstein
josheinstein / DynamicNull.cs
Created May 25, 2012 18:50
Handling "null" values in a more dynamic fashion in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Einstein.Dynamic
{
@josheinstein
josheinstein / ObservableBase.cs
Created June 6, 2012 15:05
No-frills INPC base class in C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Einstein
{