Skip to content

Instantly share code, notes, and snippets.

View jhoneill's full-sized avatar

James O'Neill jhoneill

View GitHub Profile
A0034
A0035
A0057
A0066
A0087
A0088
A0115
A0116
A0121
A0206
using namespace System.Windows.Forms.DataVisualization.Charting
using namespace System.Windows.Forms
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PsUseShouldProcessForStateChangingFunctions','',Justification='False positive. New-object does not change system state ')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectUsageOfAssignmentOperator','',Justification='False positive. New-object does not change system state ')]
param()
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms.DataVisualization
function New-FormWithSave {
[outputType([System.Windows.Forms.Form])]
# Use Set-thread-execution-state to prevent the computer sleeping. From something of Den Delimarsky's at https://den.dev/blog/caffeinate-windows/
Param ([switch]$Now, [switch]$AndDisplay )
if (-not ('win32.system' -as [type])) {Add-Type -Name System -Namespace Win32 -MemberDefinition @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
"@}
function Suspend-Sleep {
param ([switch]$AndDisplay)
function Expand-PropertyTree {
<#
.Synopis
Unrolls an object with many sub-objects.
.Example
C:> Get-Process -id $PID | Expand-PropertyTree | ft -a Path,value
Outputs the paths and values for the unrolled properties for a process object and displays path and value as a table.
By default the modules and threads properties are limited to showing on 2 of their many members
We can use -MaxArrayItems to get a different number 0 won't expand at all, and a negative number will expand ALL of them.
<#
.Synopsis
Signs a script
.DESCRIPTION
Gets a users code signing certificate, (if there is just one in "Cert:\CurrentUser\My" it will be selected automatically)
and uses it to sign a script file using a timestamping service.
Without the Time Stamp (Comodo CA is used by default) the signature is only valid for the range of dates on the certificate
If -passthrough is specified, retuns the certificate object
Else, if -quiet is specified doesn't reurn anything
Otherwise outputs the detail of the signature
#experimental response to https://github.com/PowerShell/PowerShell/issues/20750
function TabExpansion2 {
<# Options include:
RelativeFilePaths - [bool]
Always resolve file paths using Resolve-Path -Relative.
The default is to use some heuristics to guess if relative or absolute is better.
To customize your own custom options, pass a hashtable to CompleteInput, e.g.
return [System.Management.Automation.CommandCompletion]::CompleteInput($inputScript, $cursorColumn,
@{ RelativeFilePaths=$false }
using namespace System.Data
class QueryColumnCache {
#region properties. Static params for Get-SQL, query, column to use, values of that col, when to refresh
static [hashtable]$QueryParams
hidden [string]$SQLQuery
hidden [string]$SQLColumnName
hidden [timeSpan]$MaxAge
[datetime]$_LastRefresh
hidden [String[]]$Values
class SmartBuilder { # A string builder with a progress bar that automatically fluses periodically.
[System.Text.StringBuilder] hidden $Builder # The builder itself - its a sealed class otherwise the smartbuilder would be based on it.
#region supporting properties
[string]$RepeatingHeader = '' # If set, the repeating header is re-added as the first line after each flush
[scriptblock]$OnFlush = {$this.ToString()} # What to do when we flush the data (besides clearing the builder and re-adding any header) - should return a string or nothing.
[bool] hidden $_ShowProgress = $true # If false, don't show the progress bar
[string] hidden $_Activity = 'Building' # Displayed on the progress bar - accessed via $ProgressStatus
[string] hidden $_Status = 'Items so far' # Displayed on the progress bar with ": <ItemCount>" - accessed via $ProgressStatus
Set-PSReadlineOption -PredictionSource History
Set-PSReadlineOption -BellStyle None -EditMode Windows -WordDelimiters "`~!£#%^&*()=+[{]}\|;:'`",.<>/?"
Set-PSReadLineOption -Colors @{'Parameter'= "$([char]27)[97m"; 'operator'= "$([char]27)[97m"} #defaults are too dark use $([char]27) because `e doesn't work on PS 5.
Set-PSReadLineKeyHandler -Key Ctrl+RightArrow -ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
if ($cursor -lt $line.Length) {
[Microsoft.PowerShell.PSConsoleReadLine]::ForwardWord($key, $arg)
#requires -module psreadline
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
#create a hash table of VT codes
# Reverse, underline and reset; the console colors as Name, NameBackground; Markdown theme colors if present, PsReadline theme colors, and out-stream colors
if (-not $host.UI.SupportsVirtualTerminal) {$Script:VTCodes = @{}}
else {