Skip to content

Instantly share code, notes, and snippets.

View zachbonham's full-sized avatar

Zach Bonham zachbonham

View GitHub Profile
@zachbonham
zachbonham / driver.ps1
Created February 19, 2013 00:57
foreman prototype in powershell. Mainly the CTRL+C break for powershell.
$arg1 = "hello1"
$arg2 = "hello2"
$p = $(start-process -filepath .\bin\debug\hello.exe -argumentlist $arg1 -nonewwindow -passthru; start-process -filepath .\bin\debug\hello.exe -argumentlist $arg2 -nonewwindow -passthru);
#$p | wait-process
[console]::TreatControlCAsInput = $true
while($true)
@zachbonham
zachbonham / retry.ps1
Last active December 12, 2015 12:49
Retriable implementation in PowerShell completely ripped off from an implementation in Ruby.
# complete rip off of http://blog.mirthlab.com/2012/05/25/cleanly-retrying-blocks-of-code-after-an-exception-in-ruby/
#
# usage
# retriable -tries 5 -action { do-work-that-could-throw-exception }
#
function retriable($tries=3, $interval=1, [scriptblock]$action)
{
@zachbonham
zachbonham / box.ps1
Last active December 11, 2015 07:48
Internal PowerShell DSL for VM template descriptions. A Hyper-V, or Azure, provider would actually instantiate from metadata (see bottom).
set-psdebug -strict
# bleh
#
$global:boxes = @{}
<#
Here we are defining an internal PowerShell DSL for creating 'boxes'.
@zachbonham
zachbonham / unmerged.ps1
Created September 26, 2012 19:32
Reporting on unmerged changesets in TFS
<#
Report on unmerged changesets for release planning.
#>
function get_unmerged_changesets($source, $target)
{
write-host "getting unmerged changesets for $source and $target"
$changesets = @()
@zachbonham
zachbonham / crypto.cs
Created September 10, 2012 17:57
RSA public key encryption in C#
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
namespace Crtypto
{
class Program
{
static void Main(string[] args)
@zachbonham
zachbonham / bootstrap_client.ps1
Created May 8, 2012 14:59
Required foo to bootstrap a client for PowerShell Remoting
set-executionpolicy Unrestricted
winrm quickconfig -quiet
enable-wsmancredssp -role client -delegatecomputer *
@zachbonham
zachbonham / bootstrap_server.ps1
Created May 8, 2012 14:58
Required Bootstrapping of WinRM before its of any value for PowerShell Remoting
param($computername=$(throw "-computername is required"), $username=$(throw "-username is required"), $password=$(throw "-password is required"))
<#
.SYNOPSIS
Bootstraps a server for use with WinRM.
Requires running under a username which is an adminstrator on remote machine.
Requires PSEXEC from sysinternals
@zachbonham
zachbonham / remote.ps1
Created May 8, 2012 14:57
invoke-remoteexpression
function invoke-remoteexpression($computer = “\\$ENV:ComputerName”, [ScriptBlock] $expression = $(throw “Please specify an expression to invoke.”), [switch] $noProfile , $username, $password)
{
$commandLine = “echo . | powershell “
if($noProfile)
{
$commandLine += “-NoProfile “
@zachbonham
zachbonham / ServerRepository.js
Created April 28, 2012 12:55
sample type declaration in javascript
function ServerRepository(connection)
{
var servers = [
{ name : "testin 1"},
{ name: "testin 2"}
];
var self = this;
self.connection = connection;
@zachbonham
zachbonham / remoteupdate.ps1
Created February 16, 2012 16:07
Remote execution of start-bitstransfer
$cred = get-credential
$session = new-pssession -computername fqdn -credential $cred
invoke-command { import-module bitstransfer; start-bitstransfer -source \\fnp\package_1234.zip -destination c:\temp\package1234.zip } -session $session -asjob -jobname "update"
receive-job $jobid
<#
The remote use of BITS is not supported. For more information about BITS, see the MSDN documentation at http://go.microsoft.com/FWLINK/?LinkId=140888.