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 / ProxyForwarder.ps1
Created March 20, 2015 06:43
PowerShell NetMQ
# Set up the proxy forwarder ...
Add-Type -path .\NetMQ\lib\net40\NetMQ.dll
Start-Job {
try {
$context = [NetMQ.NetMQContext]::Create()
$publisher = $context.CreateXPublisherSocket()
$subscriber = $context.CreateXSubscriberSocket()
$publisher.Bind("tcp://127.0.0.1:50007");
@Jaykul
Jaykul / Example.ps1
Last active March 12, 2018 23:45
LocalizeCounterNames
$Processor, $Privileged = Get-CounterLocalizedName "Processor", "% Privileged Time"
Get-Counter "\$Processor(_Total)\$Privileged"
@Jaykul
Jaykul / MahApps.Metro.psd1
Last active August 27, 2018 17:23
MahApps.Metro
@{
ModuleVersion = '1.0'
RequiredModules = 'ShowUI'
RequiredAssemblies = '.\lib\net40\MahApps.Metro.dll'
ModuleToProcess = 'MahApps.Metro.psm1'
GUID = '36f28fcd-90dc-4278-9baa-b8544a032d84'
FunctionsToExport = @('New-CloseTabItemAction','New-SetFlyoutOpenAction','New-BindableResourceBehavior','New-BorderlessWindowBehavior','New-GlowWindowBehavior','New-WindowsSettingBehaviour','New-CustomValidationPopup','New-DataGridNumericUpDownColumn','New-LoginDialogSettings','New-CustomDialog','New-DropDownButton','New-FlipViewItem','New-FlipView','New-Flyout','New-FlyoutsControl','New-Glow','New-LayoutInvalidationCatcher','New-MetroAnimatedSingleRowTabControl','New-MetroAnimatedTabControl','New-MetroWindow','New-MetroNavigationWindow','New-MetroProgressBar','New-MetroTabControl','New-MetroTabItem','New-MultiFrameImage','New-NumericUpDown','New-Pivot','New-PivotItem','New-ScrollViewerOffsetMediator','New-SplitButton','New-WindowButtonCommands','New-WindowCommands','New-Planerator','New-ProgressRi
@Jaykul
Jaykul / Test-Error.ps1
Last active August 29, 2015 14:20
Exceptions and Errors
&{
[CmdletBinding()]param()
&{[CmdletBinding()]param() Write-Error "Demo Error 1" } -EA 0 -EV e;
$PSCmdlet.WriteError($e[0]);
1/0
&{[CmdletBinding()]param() Write-Error "Demo Error 2" } -EA 0 -EV e;
$PSCmdlet.ThrowTerminatingError($e[0])
@Jaykul
Jaykul / Some.ps1
Created May 6, 2015 00:22
Exceptions and Errors
[324]: try {
路 try{
路 throw [System.Management.Automation.ParameterBindingException]::new( "whatever",
路 [System.Management.Automation.ItemNotFoundException]::new("File Not Found"))
路 } catch{ throw $_}
路 } catch [System.Management.Automation.ParameterBindingException] { "PBE" }
路 catch [System.Management.Automation.ItemNotFoundException] { "INFE" }
PBE
[325]:
@Jaykul
Jaykul / ChildProcess.psm1
Last active March 12, 2018 23:47
ChildProcess
function Stop-ChildProcess {
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="Name")]
[String[]]$Name,
[Parameter(ValueFromPipelineByPropertyName=$true, ParameterSetName="ID")]
[Alias("ProcessID")]
[Int[]]$ID,
@Jaykul
Jaykul / FileOps.ps1
Created July 8, 2015 19:00
Simple File IO with insufficient parameter handling
function Tail-File {
[CmdletBinding()]
param($Path,
[System.Text.Encoding]$Encoding = $([System.Text.Encoding]::UTF8)
)
$File = Convert-Path $Path
try {
$Stream = New-Object System.IO.FileStream $File, "Open", "Read", "ReadWrite", 2048, "None"
@Jaykul
Jaykul / Set-BingWallpaper.ps1
Last active March 12, 2018 23:48
Set the wallpaper(s) without changing options. Sets a different wallpaper on each monitor! :-)
[CmdletBinding()]
param(
# If you want to try the bing images from other countries, fiddle around with this (try en-GB, for instance)
$Culture = 'en-US',
# If you want to (re)use yesterday's wallpapers, fiddle around with this
$Offset = 0
)
Add-Type -Assembly System.Windows.Forms, PresentationFramework
Add-Type -Name Windows -Namespace System -MemberDefinition @'
@Jaykul
Jaykul / Import-NugetLibrary.ps1
Last active March 21, 2025 14:48
(Install and) load the assemblies from a NuGet package into PowerShell
#requires -Module PackageManagement
using namespace NuGet
[CmdletBinding(DefaultParameterSetName = 'MaybeUseExisting')]
param(
[Parameter(Mandatory, Position = 0)]
[String]$Name,
[String]$Destination = "$(Split-Path $Profile)\Libraries",
[switch]$ForceReinstall,
@Jaykul
Jaykul / WhoMovedMyCheese.ps1
Created November 13, 2015 20:58
Exceptions In PowerShell
#4 I call this one: where the bleep did they put the cheese?
function Get-FileException {
param($Path)
# Assume I'm doing something with files and it throws this exception:
$fnf = [System.IO.FileNotFoundException]::new("File Not Found", $Path)
$inf = [System.Management.Automation.ItemNotFoundException]::new( "Item Not Found", $fnf)
throw $inf
}