Skip to content

Instantly share code, notes, and snippets.

View stuartpreston's full-sized avatar

Stuart Preston stuartpreston

View GitHub Profile
@stuartpreston
stuartpreston / Microsoft.Powershell_profile.ps1
Created August 18, 2014 16:37
Powershell profile that shows the execution time of the last executed command in ms.
function prompt
{
$host.ui.rawui.WindowTitle = (get-location)
$lastCommand = Get-History -Count 1
if($lastCommand) { Write-Host ("last command took") ($lastCommand.EndExecutionTime - $lastCommand.StartExecutionTime).TotalMilliseconds ("ms") }
return "PS>"
}
@stuartpreston
stuartpreston / Convert-AzureManagementCertificateToPfx.sh
Last active December 21, 2015 06:31
[MacOs] Retrieve certificate and store as .pfx from Microsoft Azure .publishsettings file
xpath downloaded.publishsettings "string(//PublishData/PublishProfile/Subscription[@Name='YOURSUBSCRIPTIONNAME']/@ManagementCertificate)" > mgmtcert.pfx
@stuartpreston
stuartpreston / Convert-AzureManagementCertificateToPfx.ps1
Created February 3, 2015 14:27
[Powershell] Retrieve certificate and store as .pfx from Microsoft Azure .publishsettings file
(Select-Xml -Path .\downloaded.publishsettings -XPath '//PublishData/PublishProfile/Subscription[@Name="YOURSUBSCRIPTIONNAME"]/@ManagementCertificate').Node.Value.ToString() | Out-File .\mgmtcert.pfx
@stuartpreston
stuartpreston / Convert-Base64EncodedDerToPem.sh
Created February 3, 2015 14:52
[OpenSSL] Convert base64 encoded DER to PEM format (e.g. to convert Microsoft Azure Management Certificate to .PEM format for cross-platform compatibility)
openssl base64 -d -A -in mgmtcert.pfx -out decoded.der
openssl pkcs12 -in decoded.der -out mgmtcert.pem -nodes
@stuartpreston
stuartpreston / Create-AzureVirtualMachineWithChefClient.ps1
Created February 13, 2015 16:15
[Powershell] Demonstrates how to create a Windows VM in Azure, adding the Chef-Client VM Extension and automatically registering the node with an accessible Chef 12 Server.
[CmdletBinding()]
param(
[string] $PublishSettingsFile = "pendrica-credentials.publishsettings",
[string] $ChefServerUrl = "https://chef.pendrica.com/organizations/azure-env-dev",
[string] $ChefValidationKey = ".chef\azure-env-dev-validator.pem",
[string] $ChefValidationClientName = "azure-env-dev-validator",
[string] $AzureSubscriptionName = "Microsoft Partner Network",
[string] $AzureImageName = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-Technical-Preview-201410.01-en.us-127GB.vhd",
[string] $AzureInstanceSize = "Standard_D1",
[string] $AzureLocation = "North Europe",
@stuartpreston
stuartpreston / winrm-profile.md
Created March 23, 2015 13:35
Dot-sourcing script on a machine via remote (e.g. WinRM) session

Example function to be saved to c:\winrm-profile.ps1

function Get-Hostname
{
  return $env:COMPUTERNAME
}

To invoke normally:

@stuartpreston
stuartpreston / Azure-AAD-Authentication-Rest.ps1
Created April 15, 2015 11:29
Some help for those using Powershell to automate Azure Resource Manager but don't want to install the Azure Powershell Cmdlets or ADAL, enter credentials in a web browser popup or set up an application as a Service Principal....
<#
.Synopsis
Retrieves a token object from the Azure OAUTH2 service without launching a credentials window.
.DESCRIPTION
Retrieves a token object that can later be used to authorise requests against the Microsoft Azure Resource Manager REST API.
.EXAMPLE
Get-AzureOauth2Token -username '[email protected]' -password 'P2ssw0rd'
#>
Function Get-AzureOauth2Token
{
@stuartpreston
stuartpreston / Keybase.md
Created June 28, 2018 01:01
Keybase proof

Keybase proof

I hereby claim:

  • I am stuartpreston on github.
  • I am stuartpreston (https://keybase.io/stuartpreston) on keybase.
  • I have a public key ASBm1MK8WvOf5nQsBgPTKT5cvEX4njjb0QS6TvcymOvcugo

To claim this, I am signing this object:

@stuartpreston
stuartpreston / install-habitat.ps1
Created April 24, 2019 09:25
Habitat install/update one-liner
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; Remove-Item $env:ProgramData\habitat -Recurse -Force -ErrorAction Ignore; $s = "https://api.bintray.com/content/habitat/stable/windows/x86_64/hab-%24latest-x86_64-windows.zip?bt_package=hab-x86_64-windows"; (New-Object System.Net.WebClient).DownloadFile($s, "$env:TEMP\habitat.zip"); Expand-Archive $env:TEMP\habitat.zip -DestinationPath $env:ProgramData -Force; Get-ChildItem -Path $env:ProgramData -Filter "hab-*" -Depth 1 | Select-Object -First 1 | Rename-Item -NewName habitat -Force; [Environment]::SetEnvironmentVariable("PATH", "$env:ProgramData\habitat;$env:SystemDrive\hab\bin;$env:PATH", "Machine");
@stuartpreston
stuartpreston / _chefconf-2019-workshop.md
Last active June 20, 2019 03:45
Snippets for the workshop: Building and deploying .NET applications with Chef Habitat and Azure Pipelines

Workshop - Get your snippets here!