Skip to content

Instantly share code, notes, and snippets.

View bgshacklett's full-sized avatar

Brian G. Shacklett bgshacklett

View GitHub Profile
@bgshacklett
bgshacklett / gist:8529451
Created January 20, 2014 21:20
Troubleshooting PS Aliases and Pipeline bindings
function Test-AliasBinding
{
[CmdletBinding()]
param(
[Alias("DNSHostName")]
[Parameter(
Mandatory=$True,
#ValueFromPipeline = $True,
ValueFromPipelineByPropertyName=$True
$worldTab = @{}
$esxcli = Get-EsxCli
$esxcli.vm.process.list() | %{
$worldTab.Add($_.WorldID,$_.DisplayName)
}
@bgshacklett
bgshacklett / Get-Ec2InstanceDetails
Last active September 3, 2016 04:02
Powershell Snippets
Get-EC2Instance | Select-Object -ExpandProperty instances | Select-Object InstanceId, @{Name='Name'; Expression={$_.Tags | Where-Object { $_.Key -like 'Name'} | Select-Object -ExpandProperty Value }}, InstanceType, @{Name='AMI'; Expression={Get-EC2Image -ImageId $_.ImageID | Select-Object -ExpandProperty name}}, @{Name='StorageConfig'; Expression={"Storage"}}, @{Name='SubnetName'; Expression={Get-Ec2Subnet -SubnetId $_.SubnetId | Select-Object -ExpandProperty Tags | Where-Object { $_.Key -like 'Name' } | Select-Object -ExpandProperty Value }} | Sort-Object -Property Name | Out-GridView
@bgshacklett
bgshacklett / gist:4fd3fc1fb6e777dbfad853614ee5b735
Last active September 1, 2016 03:35
Useful Bash OneLiners
# From http://stackoverflow.com/questions/191364/quick-unix-command-to-display-specific-lines-in-the-middle-of-a-file
# Print lines 20 to 40 of a text file:
sed -n '20,40p;41q' file_name
@bgshacklett
bgshacklett / README.md
Last active November 18, 2016 20:57
Useful Git Commands

These are some commands that I've found useful over my time working with Git.

@bgshacklett
bgshacklett / powerShellOneLiners.ps1
Created March 2, 2017 21:53
Useful PowerShell One-Liners
# Get any command that has $ParameterName as an available parameter:
Get-Command | Where-Object { $_.parametersets.parameters.Name -eq "$ParameterName" }
@bgshacklett
bgshacklett / VimSnippets.md
Last active May 26, 2017 22:39
Vim Snippets

A collection of useful Vim snippets

@bgshacklett
bgshacklett / Reduce-Object.ps1
Created December 17, 2017 03:21
An Implementation of the Reduce Function for PowerShell
function Reduce-Object
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
$InitialValue,
[Parameter(ValueFromPipeline = $true)]
$InputObject,
$certParams =
@{
Type = 'Custom'
KeyUsage = 'DigitalSignature'
FriendlyName = 'WindowsTerminal'
CertStoreLocation = 'Cert:\LocalMachine\My'
Subject = (
'CN=Microsoft Corporation',
'O=Microsoft Corporation',
'L=Redmond',
@bgshacklett
bgshacklett / ConvertFrom-PosixEnvironment.ps1
Created November 21, 2019 14:25
A PowerShell Script/Function which takes a Posix environment (output by env, for instance) and converts it to a PowerShell environment format.
param
(
[Parameter(ValueFromPipeline="true")]
[String]$PosixVars
)
Process
{
$PosixVars `
| ForEach-Object {