Skip to content

Instantly share code, notes, and snippets.

Get-ChildItem -Directory |%{
cd $_.FullName
git pull
cd..
}
@stuartleeks
stuartleeks / baz
Last active August 29, 2015 14:16
dummy gist
baz
@stuartleeks
stuartleeks / dockerps.ps1
Last active August 29, 2015 14:25
PowerShell-friendly docker ps parsing
function PascalName($name){
$parts = $name.Split(" ")
for($i = 0 ; $i -lt $parts.Length ; $i++){
$parts[$i] = [char]::ToUpper($parts[$i][0]) + $parts[$i].SubString(1).ToLower();
}
$parts -join ""
}
function GetColumnInfo($headerRow, $propertyNames){
$lastIndex = 0
$lastName = $null
@stuartleeks
stuartleeks / AzureRmAuth.ps1
Created November 5, 2015 21:01
Hack to get AccessToken for ARM from current PowerShell context
# Working on 1.0.0 preview of Azure PowerShell cmdlets
function GetAccessToken(){
$psContext = Get-AzureRmContext
$context = [Microsoft.Azure.Common.Authentication.Models.AzureContext] $psContext
$account = $context.Account
$environment= $context.Environment
$tenant = $context.Tenant
$authFactory = [Microsoft.Azure.Common.Authentication.AzureSession]::AuthenticationFactory
@stuartleeks
stuartleeks / GetDeploymentOperationFailures.sh
Last active November 26, 2015 14:17
ARM deployment operations - bash, CLI
#!/bin/bash
# Pass the resource group name as the 1st parameter to this script
# Pass the number of deployments to skip as the 2nd parameter (optional)
resourceGroupName=$1
if [ "x$2" = "x" ]; then deploymentsToSkip=0; else deploymentsToSkip=$2; fi
# Get the name of the last deployment
deploymentName=$(azure group deployment list $resourceGroupName --json | jq "[.[] | {name:.name, timestamp: .properties.timestamp } ] | sort_by(.timestamp) | reverse | .[$deploymentsToSkip].name" --raw-output)
# Get failed operations for the last deployment
@stuartleeks
stuartleeks / OpenUiSideLoad.ps1
Last active February 18, 2016 12:42
Marketplace helper scripts
param(
[parameter(Mandatory=$true, ValueFromPipeline)]
[object[]] $blobs,
[parameter()]
$uiDefinitionFilename = "createUiDefinition.json"
)
process{
$uiBlob = $blobs | ?{ $_.Name -eq $uiDefinitionFilename} | select -First 1
if ($uiBlob -ne $null){
@stuartleeks
stuartleeks / CustomConfigurationManager.cs
Last active October 13, 2016 12:23
CustomConfigurationManager - pre ASP.NET 5 helper for working with environment variables for app settings
using System;
using System.Configuration;
public static class CustomConfigurationManager
{
private static CustomAppSettings _appSettings = new CustomAppSettings();
public static CustomAppSettings AppSettings { get { return _appSettings; } }
}
public class CustomAppSettings
{
@stuartleeks
stuartleeks / SetStorageCorsOptions
Created November 13, 2015 10:54
Command to set the CORS options for a storage account using Azure xplat CLI
# replace account name, key and cors rules
# ... and yes, I've regenerated my key since pasting ;-)
azure storage cors set --account-name slsas --account-key fkc8U4c86RotjO/VHg4jNKVUO+OsmkVvK+a800zhAcB6HQTVCFLRaiIAvJ9UaciFNmpgGHkod5731WGpw3+k7Q== --blob --cors '[{"AllowedMethods":["GET","OPTIONS","PUT"],"AllowedOrigins":["https://corsstoragetest.azurewebsites.net"],"AllowedHeaders":["Accept","Accept-Encoding","Accept-Language","Access-Control-Request-Headers","Access-Control-Request-Method","Cache-Control","Connection","Content-Type","DNT","Host","Origin","Pragma","Referer","User-Agent","x-ms-blob-content-type","x-ms-blob-type"],"ExposedHeaders":[],"MaxAgeInSeconds":60}]'
@stuartleeks
stuartleeks / ImportAzureVmsIntoRdcMan.ps1
Last active February 24, 2017 15:43
PowerShell script to create a Remote Desktop Connection Manager configuration file for all Windows Azure Virtual Machines in a subscription.Requires Azure PowerShell cmdlets: http://www.windowsazure.com/en-us/documentation/articles/install-configure-powershell/. See this blog post for more info: http://blogs.msdn.com/b/stuartleeks/archive/2014/0…
$rdcmanName = "Azure VMs"
$outputFileName = Get-Location | Join-Path -ChildPath "AzureVMs.rdg"
$xml = [xml]'<?xml version="1.0" encoding="utf-8"?>
<RDCMan schemaVersion="1">
<version>2.2</version>
<file>
<properties>
<name>blog</name>
<expanded>True</expanded>
@stuartleeks
stuartleeks / Gert-Lush.ps1
Created January 22, 2016 08:41
Gripping powershell fun ;-)
get-command Get* | %{ set-alias -name ($_ -replace "^Get","Gert") -Value $_ }