This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]$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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function one {[cmdletbinding()]param() | |
begin {Write-Host "one begins"} end {Write-host "one ends"} | |
process {1,2,3} | |
} | |
function two {param ([parameter(ValueFromPipeline)]$p) | |
begin {Write-Host "two begins"} end {Write-host "two ends"} | |
process { | |
if ($p -eq 2) {$p / 0 } # cause a division by zero error | |
$p | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function binaryout { | |
<# | |
.SYNOPSIS | |
Workaround for PowerShell processing the output of all external programs as strings | |
.DESCRIPTION | |
PowerShell treats any output from an external program as string which should be | |
split whenever it sees LF or CR LF. As a workround this calls the program with | |
Start-Process and redirects standard output to a file - on completion the file | |
is read and sent as a bytestream to the next process. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Error { | |
[cmdletbinding(DefaultParameterSetName='Newest')] | |
param ( | |
[Parameter(Position = 0, ValueFromPipeline=$true, ParameterSetName= "Error")] | |
[ValidateNotNullOrEmpty()] | |
$InputObject, | |
[Parameter(ParameterSetName = "Newest", ValueFromPipelineByPropertyName = $true)] | |
[Alias('Last')] | |
[ValidateRange(1, [int]::MaxValue)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Configuration><ViewDefinitions> | |
<View><Name>MatchInfo</Name> | |
<ViewSelectedBy><TypeName>Microsoft.PowerShell.Commands.MatchInfo</TypeName></ViewSelectedBy> | |
<CustomControl><CustomEntries><CustomEntry><CustomItem><ExpressionBinding><ScriptBlock> | |
#defaults are equivalent to $MatchInfoPreference =@{$Prefix='> '; $MatchVTSeq=$PSStyle.Reverse; $PathVTSeq=''; $NumberVTSeq=''; $ContextVTSeq=''} | |
$ResetVTSeq = $PSStyle.Reset | |
$Prefix = '> ' | |
if (-not $MatchInfoPreference) {$MatchVTSeq = $PSStyle.Reverse } | |
else { | |
$MatchVTSeq = $MatchInfoPreference.MatchVTSeq |
NewerOlder