Skip to content

Instantly share code, notes, and snippets.

View heaths's full-sized avatar

Heath Stewart heaths

View GitHub Profile
@heaths
heaths / X509Certificate2.psm1
Last active June 2, 2024 00:33
X509Certificate2 PowerShell module
#Requires -Version 6.0
using namespace System.Security.Cryptography
using namespace System.Security.Cryptography.X509Certificates
using namespace System.Text
<#
.Synopsis
Generate an X509 v3 certificate.
@heaths
heaths / Program.cs
Last active October 23, 2020 17:36
Simple ImportCertificate sample
// Copyright 2020 Heath Stewart
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
@heaths
heaths / Program.cs
Last active January 13, 2021 01:16
Example of using EC keys to sign remotely using Key Vault and verify locally
// #r "nuget:Azure.Identity,1.3.0"
// #r "nuget:Azure.Security.KeyVault.Keys,4.1.0"
// #r "nuget:System.CommandLine.DragonFruit,0.3.0-alpha.20574.7"
using System;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Azure;
using Azure.Identity;
@heaths
heaths / main.go
Created February 24, 2021 17:38
Sample for creating an RSA key, wrapping and unwrapping an AES key in Key Vault using Golang
package main
import (
"context"
"fmt"
"os"
"strings"
"net/url"
@heaths
heaths / azure-cli.md
Last active May 7, 2025 17:37
Tips and other useful commands for the Azure CLI

Some useful commands for the Azure CLI. Also check out JMESPath specifications for other functions you can use.

Principals

Get the principal OID for a given client ID in a tenant:

# add `--output tsv` to get the raw value without quotes
az ad sp show --id $id --query objectId
@heaths
heaths / Remove-AzSdkResourceGroups.ps1
Last active April 1, 2021 20:18
Example script to delete expired or non-standard named resource groups
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#Requires -Version 6.0
#Requires -PSEdition Core
#Requires -Modules @{ModuleName='Az.Accounts'; ModuleVersion='1.6.4'}
#Requires -Modules @{ModuleName='Az.Resources'; ModuleVersion='1.8.0'}
@heaths
heaths / Test-SampleMetadata.ps1
Last active April 15, 2021 00:20
Find invalid sample metadata in Azure SDK samples' markdowns
[CmdletBinding(DefaultParameterSetName='Path')]
param (
[Parameter(ParameterSetName='Path', Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[string[]] $Path,
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Alias('PSPath')]
[string[]] $LiteralPath,
[Parameter()]
@heaths
heaths / config.yml
Created May 11, 2021 23:04
GitHub CLI aliases
# Aliases allow you to create nicknames for gh commands
aliases:
co: pr checkout
# The following aliases require https://github.com/cli/cli/pull/3519
issues: |-
issue list --json number,title,labels,updatedAt --template '{{range .}}{{if .labels}}{{row (printf "#%v" .number | autocolor "green") .title (pluck "name" .labels | join ", " | printf "(%s)" | autocolor "gray+h") (timeago .updatedAt | printf "about %s" | autocolor "gray+h")}}{{else}}{{row (printf "#%v" .number | autocolor "green") .title "" (timeago .updatedAt | printf "about %s" | autocolor "gray+h")}}{{end}}{{end}}'
users: |-
api graphql --paginate
--template '{{range .data.repository.assignableUsers.nodes}}{{if .status}}{{row (autocolor "green" .login) .name (autocolor "gray+h" .email) (autocolor "yellow" .status.message)}}{{else}}{{row (autocolor "green" .login) .name (autocolor "gray+h" .email) ""}}{{end}}{{end}}'
@heaths
heaths / ConvertTo-Rtf.ps1
Created September 18, 2021 16:10
Script to convert simple text e.g. LICENSE.txt to basic RTF for display in a RichEdit2.0 control
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0)]
[string] $Path,
[Parameter(Mandatory=$true, Position=1)]
[string] $OutFile,
[Parameter()]
[ValidateNotNullOrEmpty()]
@heaths
heaths / SecureFile.psm1
Last active March 30, 2022 17:21
Use Windows DPAPI to secure files
#Requires -Version 5.0
function Protect-SecureFile {
[CmdletBinding(DefaultParameterSetName = 'Path')]
param (
[Parameter(ParameterSetName = 'Path', Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string] $Path,
[Parameter(ParameterSetName = 'LiteralPath', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('PSPath')]