Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
stuartleeks / ConvertFromDocker.ps1
Last active October 31, 2019 18:52
ConvertFrom-Docker
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 GetHeaderBreak($headerRow, $startPoint=0){
$i = $startPoint
while( $i + 1 -lt $headerRow.Length)
@stuartleeks
stuartleeks / GetDeploymentErrors.ps1
Created November 11, 2015 14:04
ARM deployment operation utils
# gets information for non-succeeded deployment operations for the last deployment for the resource group specified in $resourceGroupName
Get-AzureResourceGroupDeployment -ResourceGroupName $resourceGroupName | sort -Descending -Property Timestamp | select -First 1 | Get-AzureResourceGroupDeploymentOperation | ?{ $_.Properties.ProvisioningState -ne "Succeeded" } | select -ExpandProperty Properties | ConvertTo-Json
@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 / GetDeploymentOperationSummary.ps1
Created November 13, 2015 10:00
ARM deployment operations - PowerShell, CLI
param($resourceGroupName)
# note that this requires jq: https://stedolan.github.io/jq/download/
$deploymentName=$(azure group deployment list $resourceGroupName --json | jq "[.[] | {name:.name, timestamp: .properties.timestamp } ] | sort_by(.timestamp) | reverse | .[0].name" --raw-output)
azure group deployment operation list --resource-group $resourceGroupName --name $deploymentName --json | jq '[.[] | .properties | { provisioningState : .provisioningState, timestamp: .timestamp, resourceType:.targetResource.resourceType,resourceName:.targetResource.resourceName}] | sort_by(.timestamp)'
@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 / AzureHelpers.ps1
Created November 25, 2015 13:47
A set of functions/cmdlets to simplify working with the Azure PowerShell cmdlets
<#
# Helper function for other cmdlets
#>
function ParseOperationDuration($durationString){
# expected behaviour (should put in tests)
#(ParseOperationDuration "PT21.501S").ToString() # Timespan: 21.501 seconds
#(ParseOperationDuration "PT5M21.501S").ToString() # Timespan: 5 minutes 21.501 seconds
#(ParseOperationDuration "PT1H5M21.501S").ToString() # Timespan: 1 hour 5 minutes 21.501 seconds
#(ParseOperationDuration "PT 21.501S").ToString() # throws exception for unhandled format
@stuartleeks
stuartleeks / GenerateTemplateParameters.ps1
Created January 14, 2016 21:05
Generate parameters for Azure Resource Manager template
param(
$templateFile,
[switch] $includeParametersWithDefaults
)
$template = Get-Content $templateFile | ConvertFrom-Json
function getDefaultValue($type){
switch ($type){
"bool" {'false'}
"int" {0}
@stuartleeks
stuartleeks / Gert-Lush.ps1
Created January 22, 2016 08:41
Gripping powershell fun ;-)
get-command Get* | %{ set-alias -name ($_ -replace "^Get","Gert") -Value $_ }
@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){
function OutputStatus($message){
try {
[Console]::SetCursorPosition(0,0)
Write-Host $message.PadRight([Console]::BufferWidth)
}
catch [System.IO.IOException] {
## IO Exception when unable to set position
}
}
$messages = @()