Skip to content

Instantly share code, notes, and snippets.

View Jaykul's full-sized avatar
😀
Learning

Joel Bennett Jaykul

😀
Learning
View GitHub Profile
@Jaykul
Jaykul / Update-ParameterValues.ps1
Created November 21, 2015 06:17
PSBoundParameterValues++
Update-TypeData -TypeName System.Management.Automation.InvocationInfo -MemberName ParameterValues -MemberType ScriptProperty -Value {
$results = @{}
foreach($parameter in $this.MyCommand.Parameters.GetEnumerator()) {
try {
$key = $parameter.Key
if($value = Get-Variable -Name $key -Scope 1 -ValueOnly -ErrorAction Ignore) {
$results.$key = $value
}
} finally {}
}
@Jaykul
Jaykul / Demo.ps1
Last active November 24, 2015 00:49
PowerShell 5 Classes (v 10586)
PS> mkdir ClassContainer
Directory: C:\Users\Joel\Documents\WindowsPowerShell\TestData\modules
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/23/2015 7:41 PM ClassContainer
@Jaykul
Jaykul / Catalog.cs
Last active January 22, 2016 21:01
The wonderful world of CliXml output
// You can output any simple .Net Object that you like
using System;
using System.Collections.Generic;
using System.Management.Automation;
namespace PoshCode
{
// A data object we're going to output
public class Vehicle
{
@Jaykul
Jaykul / ConEmu.xml
Created December 30, 2015 22:22
ConEmu Configuration
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2015-12-30 15:59:33" build="151224">
<value name="StartType" type="hex" data="02"/>
<value name="CmdLine" type="string" data=""/>
<value name="StartTasksFile" type="string" data=""/>
<value name="StartTasksName" type="string" data="{PowerShell}"/>
<value name="StartFarFolders" type="hex" data="00"/>
<value name="StartFarEditors" type="hex" data="00"/>
@Jaykul
Jaykul / Example.ps1
Last active May 13, 2018 13:08
WriteError or Write-Error versus ThrowTerminatingError and Throw
PS$ @'
>> [CmdletBinding()]param()
>>
>> Write-Host "Imagine you're doing some work and you call a command from my module..."
>> Test-Failures "Throw" -ErrorAction Continue
>> '@ > ~\Documents\WindowsPowerShell\Scripts\TestFailureMode.ps1
PS$ ~\Documents\WindowsPowerShell\Scripts\TestFailureMode.ps1
Imagine you're doing some work and you call a command from my module...
@Jaykul
Jaykul / BlockChain Verification
Created January 5, 2016 20:58
BlockChain Verification
Verifying that +jaykul is my blockchain ID. https://onename.com/jaykul
@Jaykul
Jaykul / AttributesExist.ps1
Last active March 12, 2018 23:58
Parsing PowerShell with Reflection Module
<#PS #> Add-Type @"
using System;
using System.Collections.Generic;
[Flags]
public enum ServicesEnum
{
ExOnline = 1,
MsOnline = 2,
@Jaykul
Jaykul / GitHub.psm1
Created January 29, 2016 17:59
GitHub Helper Functions
function Get-GithubRelease {
[CmdletBinding()]
param(
# The user or organization that owns the repository
[Parameter(Mandatory)]
$Owner,
# The name of the project repository
[Parameter(Mandatory)]
$Repo,
# The release id. Defaults to "latest" (e.g. v15.0 or "latest")
@Jaykul
Jaykul / TupleSample1.ps1
Created February 3, 2016 20:14
Tuple Structs in PowerShell
<# PS 1:#> Update-TypeData -TypeName User -MemberType AliasProperty -MemberName FirstName -Value Item1
<# PS 2:#> Update-TypeData -TypeName User -MemberType AliasProperty -MemberName LastName -Value Item2
<# PS 3:#> Update-TypeData -TypeName User -MemberType AliasProperty -MemberName Seniority -Value Item3
<# PS 4:#> Update-TypeData -TypeName User -MemberType AliasProperty -MemberName JobRole -Value Item4
<# PS 5:#> Update-TypeData -TypeName User -DefaultDisplayPropertySet @("FirstName","LastName","Seniority","JobRole")
<# PS 6:#> [Tuple]::Create("Joel","Bennett",11,"Principal Software Engineer") | %{ $_.PSTypeNames.Insert(0, "User"); $_ }
FirstName LastName Seniority JobRole
--------- -------- --------- -------
Joel Bennett 11 Principal Software Engineer
@Jaykul
Jaykul / Format-Wide.ps1
Created February 24, 2016 05:30
A Format-Wide that can pivot the output and order it vertically
function Format-Wide {
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113304')]
param(
[Parameter(Position=0)]
[System.Object]
${Property},
[switch]
${AutoSize},