Skip to content

Instantly share code, notes, and snippets.

View ChrisLGardner's full-sized avatar

Chris Gardner ChrisLGardner

View GitHub Profile
@Jaykul
Jaykul / SubscriptionNameCompleterAttribute.ps1
Last active September 14, 2020 10:55
Bonus Argument Completers For Azure
using namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
using namespace System.Management.Automation.Language
using namespace System.Management.Automation
using namespace System.Collections.Generic
using namespace System.Collections
[AttributeUsage("Property,Field")]
class SubscriptionNameCompleter : ArgumentCompleterAttribute {
# PowerShell expects you to write IArgumentCompleter and register them with this syntax:
# [ArgumentCompleter([MyIArgumentCompleter])]
@brettmillerb
brettmillerb / Get-AzCachedAccessToken.ps1
Created March 15, 2019 13:22
Get-AzCachedAccessToken
function Get-AzCachedAccessToken {
<#
.SYNOPSIS
Get the Bearer token from the currently set AzContext
.DESCRIPTION
Get the Bearer token from the currently set AzContext. Retrieves from Get-AzContext
.EXAMPLE
Get-AzCachedAccesstoken
@IISResetMe
IISResetMe / Resolve-MemberChain.ps1
Created February 12, 2019 12:08
Recursively dereference powershell instance members without actually resorting to recursion
function Resolve-MemberChain
{
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[psobject[]]$InputObject,
[Parameter(Mandatory = $true, Position = 0)]
[string[]]$MemberPath,
[Parameter(Mandatory = $false)]
function Get-ArgumentCompleter {
<#
.SYNOPSIS
Get custom argument completers registered in the current session.
.DESCRIPTION
Get custom argument completers registered in the current session.
By default Get-ArgumentCompleter lists all of the completers registered in the session.
.EXAMPLE
Get-ArgumentCompleter
@nohwnd
nohwnd / deffer.ps1
Created December 21, 2018 09:16
Deffered evaluation for logs
# Logging verbose info to screen is useful for debugging
# but the info is hidden 99% of the time. Problem is that
# evaluating a string to get the verbose message will run
# even if we never actually print it, adding overhead to
# every run, not just runs that are verbose.
# to avoid this passing a script block that evaluates to the
# message string conditionally seems to work well
@indented-automation
indented-automation / Get-StrictMode.ps1
Last active August 2, 2018 11:58
Gets the strict mode version for the current scope
function Get-StrictMode {
[CmdletBinding()]
param (
[Switch]$All
)
[Reflection.BindingFlags]$flags = 'Instance, NonPublic'
try {
# SessionStateInternal