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 / ScriptPropertyRecalculatesVariable.ps1
Last active April 8, 2018 01:35 — forked from pinecones-sx/fcobject.ps1
How to capture a variable value in a closure
function global:Get-CompFolder{
param($iFolderLoc)
$objCompFolder = [Ordered]@{
'Location' = $iFolderLoc
'Folder' = Get-Item $iFolderLoc
'SortedTree' = @()
}
New-Object -TypeName PSObject -Property $objCompFolder |
Add-Member -Passthru -Type ScriptProperty -Name Tree -Value {
@Jaykul
Jaykul / FileTypes.ANSI.Format.ps1xml
Last active March 13, 2018 00:10
ANSI Escape Sequences
<?xml version="1.0" encoding="utf-8" ?>
<!-- *******************************************************************
This is Joel "Jaykul" Bennett's coloring format file for PowerShell 5.1
******************************************************************** -->
<Configuration>
<SelectionSets>
<SelectionSet>
<Name>FileSystemTypes</Name>
<Types>
<TypeName>System.IO.DirectoryInfo</TypeName>
@Jaykul
Jaykul / ShouldProcess.psm1
Last active March 27, 2019 14:44
Demo SupportsShouldProcess
function Test-Confirm {
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="Medium")]
param([Switch]$Force)
$RejectAll = $false;
$ConfirmAll = $false;
Write-Verbose "ConfirmPreference is $ConfirmPreference"
foreach($file in ls) {
if($PSCmdlet.ShouldProcess( "Removed the file '$($file.Name)'",
@Jaykul
Jaykul / Build.ps1
Created June 23, 2016 06:50
ModuleBuilder
#Requires -Version "4.0" -Module PackageManagement
#requires -Module Configuration
#requires -Module Pester
[CmdletBinding()]
param(
# The step(s) to run. Defaults to "Clean", "Update", "Build", "Test", "Package"
# You may also "Publish"
# It's also acceptable to skip the "Clean" and particularly "Update" steps
[ValidateSet("Clean", "Update", "Build", "Test", "Package", "Publish")]
[string[]]$Script:Step = @("Clean", "Update", "Build", "Test", "Package"),
@Jaykul
Jaykul / PowerShellGet.psm1
Last active December 15, 2020 08:12
PowerShell Gallery Module - Light
function Find-Module {
<#
.Synopsis
A wrapper for Invoke-RestMethod to search the PowerShell Gallery
.Description
In order to support wildcards, we build pretty complicated URLs,
and then we filter the results by title
#>
[CmdletBinding()]
param (
@Jaykul
Jaykul / PowerShell-Malmo-0.ps1
Last active July 13, 2016 16:14
Driving Minecraft from PowerShell
#requires -version 5.0
using assembly MalmoNet.dll
using namespace Microsoft.Research.Malmo
[Environment]::CurrentDirectory = $PSScriptRoot
$ErrorActionPreference = "Stop"
$agentHost = [AgentHost]::new()
$mission =[MissionSpec]::new()
$missionRecord = [MissionRecordSpec]::new("$PSScriptRoot\saved_data.tgz")
@Jaykul
Jaykul / PSModule.psm1
Last active May 3, 2022 09:18
A workaround for getting things from the PowerShellGallery (works for nuget too) when you don't have PowerShellGet or nuget
function Find-NugetPackage {
#.SYNOPSIS
# Find a package in a v2 repository
[Alias("Find-PSModule")]
[CmdletBinding()]
param(
# The name of a package to find
[Parameter(Mandatory)]
$Name,
# The repository api URL (with trailing slash) -- like https://www.powershellgallery.com/api/v2/ or https://www.nuget.org/api/v2/
@Jaykul
Jaykul / Set-Volume.ps1
Created July 19, 2016 18:00
Playing With Volume...
Add-Type -Path C:\Users\JBennett\Source\Repos\SoundUtils\SoundUtils\SoundUtils.cs
$volume = [WOSI.Utilities.EndpointVolume]::new()
$volume | gm
foreach($channel in 0..($volume.GetChannelCount()-1)) {
[PSCustomObject]@{Channel = $channel; Volume = $volume.GetChannelVolume($channel) }
}
$volume.SetChannelVolume(0, 0.5)
@Jaykul
Jaykul / Get-MsdnKeys.ps1
Last active August 3, 2022 20:28
PowerShell + Selenium Demo: Getting Started, and reusing cookies with Invoke-Request
# It might work in 4, but I'm not testing there. Lower you'll have to tweak code
#requires -Version 5.0
param(
# Your Live ID for MSDN login
[Parameter(Mandatory)]
[PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential,
# Pick a browser to use. Defaults to Firefox (which doesn't seem to require an external Driver file)
@Jaykul
Jaykul / History.Formats.ps1xml
Last active March 13, 2018 00:18
How history should have been ...
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<View>
<Name>history</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.HistoryInfo</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>