Skip to content

Instantly share code, notes, and snippets.

@gpduck
gpduck / CarCdr.ps1
Created August 12, 2015 21:47
Powershell CAR and CDR
function car {
[CmdletBinding(DefaultParameterSetName='DefaultParameter', HelpUri='http://go.microsoft.com/fwlink/?LinkID=113387', RemotingCapability='None')]
param(
[Parameter(ValueFromPipeline=$true)]
[psobject]
${InputObject},
[Parameter(ParameterSetName='SkipLastParameter', Position=0)]
[Parameter(ParameterSetName='DefaultParameter', Position=0)]
[System.Object[]]
@gpduck
gpduck / StartTempRabbitMQ.ps1
Created July 13, 2015 20:33
Startup a temporary RabbitMQ Server
$TempPath = [IO.Path]::GetTempPath()
$SBin = "C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.5.3.60710\sbin"
$NodeNameBase = [IO.Path]::GetFileNameWithoutExtension([IO.Path]::GetRandomFileName())
$NodeName = "$NodeNameBase@$Env:COMPUTERNAME"
$RabbitBase = Join-Path $TempPath $NodeNameBase
$ErlangHome = "c:\Program Files\erl7.0"
$RabbitPort = 5672
$MgmtPort = 15672
@gpduck
gpduck / cCmsMessage.psm1
Last active August 29, 2015 14:21
Adds CmsMessage commands that should be mostly compatible with the ones provided in v5 to down-level PowerShell.
<#
Copyright 2015 Chris Duck
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@gpduck
gpduck / gist:f64aaea6f3aa87a4049d
Created April 9, 2015 00:02
Module Verb Coverage
$ModuleName = "YourModule"
$Verbs = Get-Command -Module $ModuleName | Select -Unique -ExpandProperty Verb | Sort
Get-Command -Module $ModuleName | Group Noun | %{
$Cmds = $_.Group
$Noun = $_.Name
$VerbCoverage = [Ordered]@{
Noun = $Noun
}
<#
.DESCRIPTION
Outputs the SSL protocols that the client is able to successfully use to connect to a server.
.NOTES
Copyright 2014 Chris Duck
http://blog.whatsupduck.net
Licensed under the Apache License, Version 2.0 (the "License");
@gpduck
gpduck / gist:3fd36df7714d9860f5ad
Created February 28, 2015 03:05
Cyclic Dependency
$ModulePath = Join-Path $env:USERPROFILE "Documents\WindowsPowerShell\Modules"
"m1","m2","m3","m4","m5","m6" | %{ mkdir (Join-Path $ModulePath $_ ) -ea 0 }
New-ModuleManifest -Path (Join-Path $ModulePath "m1\m1.psd1") -RequiredModules "m5","m2"
New-ModuleManifest -Path (Join-Path $ModulePath "m2\m2.psd1") -RequiredModules "m3","m4"
New-ModuleManifest -Path (Join-Path $ModulePath "m3\m3.psd1") -RequiredModules "m4"
New-ModuleManifest -Path (Join-Path $ModulePath "m4\m4.psd1") -RequiredModules "m5"
New-ModuleManifest -Path (Join-Path $ModulePath "m5\m5.psd1")
@gpduck
gpduck / gist:3590063df45e193c4652
Created January 29, 2015 23:21
Get-TagAssignment Bug
$VMHost = "yourhost"
New-TagCategory -Name "TestCat"
New-Tag -Name "TestTag" -Category "TestCat"
New-VM -Name "test/tag" -vmhost $VMHost
New-TagAssignment -Tag TestTag -Entity "test/tag"
Get-TagAssignment -Category "TestCat" | %{$_.entity} | fl
@gpduck
gpduck / Script.Tests.ps1
Created November 7, 2014 22:13
Testing a script file in a module
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
Describe "Some-Function" {
Mock "Export-ModuleMember" -ParameterFilter { $Function -eq "Some-Function" } -Verifiable
#I've moved this down here, is this OK?
. "$here\$sut"
Context "Other Tests" {
@gpduck
gpduck / UnpackAb.groovy
Created May 13, 2014 07:51
Unpack an Android adb backup using groovy
import java.util.zip.*
String backupFile = "c:\\backup.ab";
String outFile = "c:\\backup.tar";
int skip = 0;
System.setProperty("line.separator", (String)(char)10);
File f = new File(backupFile);
FileInputStream fis = new FileInputStream(f);
InputStreamReader sr = new InputStreamReader(fis);
@gpduck
gpduck / IseFileChangeNotifications.ps1
Created May 6, 2014 05:05
A crude attempt at providing file change notifications for ISE.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") > $Null
$Watchers = @{}
$TabCollectionChangedEvent = {
$EventArgs.NewItems | %{
Register-ObjectEvent -InputObject $_.Files -EventName CollectionChanged -Action $FileCollectionChangedEvent
}
}
$FileCollectionChangedEvent = {