Skip to content

Instantly share code, notes, and snippets.

View jhoneill's full-sized avatar

James O'Neill jhoneill

View GitHub Profile
@jhoneill
jhoneill / demo.ps1
Last active February 15, 2022 08:17
# rev 0.2 added more comments, and made the regax a bit more precise.
function SplitEmUp {
param (
$paramString
)
#This regex will isolate quoted blocks e.g. " -example )( $quote "
# and will identify matching open and close () {} and [] even if nested.
$opensAndCloses = @'
(?x) # Allow comments and ignore spaces and line breaks in the layaout.
^(?> # Start and make the repeating group ‘atomic’.
@jhoneill
jhoneill / Remove-SoftDeletedAPIService.ps1
Last active July 14, 2021 08:07
Re-deploying the API management service fails and help says call the REST API: here's a script to do it.
<#
.synopsis
Remove Soft-deleted API Management service
.description
Re-deploying the API management service fails with a message
See https://aka.ms/apimsoftdelete
That says call the REST API. This does that.
#>
[cmdletbinding(SupportsShouldProcess=$true,confirmImpact='High' )]
param (
####
#### Proxy function to restore Writing the URI to verbose when calling Invoke-RestMethod
#### When calling out of a module -Verbose isn't inherited so the function fiddles verbosepreference as a parameter.
Function Invoke-RestMethod {
[CmdletBinding(DefaultParameterSetName='StandardMethod', HelpUri='https://go.microsoft.com/fwlink/?LinkID=2096706')]
<#
.ForwardHelpTargetName Microsoft.PowerShell.Utility\Invoke-RestMethod
.ForwardHelpCategory Cmdlet
#>
param(
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<SelectionSets><SelectionSet>
<Name>FileSystemTypes</Name>
<Types>
<TypeName>System.IO.DirectoryInfo</TypeName>
<TypeName>System.IO.FileInfo</TypeName>
</Types>
</SelectionSet></SelectionSets>
<?xml version="1.0" encoding="utf-8" ?>
<!-- *******************************************************************
Copyright (c) James O'Neill 2022 - Shared under the MIT License https://mit-license.org/
Allows [consoleColor] to be used like this
ps > [ConsoleColor]::Red.Foreground("This is red")
ps > [ConsoleColor]::DarkYellow.Background([ConsoleColor]::red.Foreground("This is red on darkyellow"))
<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
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)]
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.
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
}