Skip to content

Instantly share code, notes, and snippets.

@DBremen
DBremen / Get-Choice.ps1
Last active December 6, 2021 21:11
An alternative to the built-in PromptForChoice providing a consistent UI across different hosts
#An alternative to the built-in PromptForChoice providing a consistent UI across different hosts
function Get-Choice {
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,Position=0)]
$Title,
[Parameter(Mandatory=$true,Position=1)]
[String[]]
@DBremen
DBremen / ConvertToJIRATable.vb
Created September 10, 2015 19:52
VBA Excel to convert an Excel Table to JIRA Wiki Markup
Sub ConvertToJiraTable()
Dim workingRange As Range, currCol As Range, currRow As Range
Dim rowIndex As Long, colIndex As Long
Dim output As String, cellVal As String, status As String
Dim statusHash As Dictionary
Dim cb As DataObject
Set cb = New DataObject
Set statusHash = New Dictionary
statusHash("Done") = "(/)"
statusHash("Not Done") = "(x)"
@DBremen
DBremen / Add-PowerShellContextMenu.ps1
Last active November 5, 2025 15:40
Function to add context menu entries to open PowerShell command prompt and edit a file with PowerShell ISE
function Add-PowerShellContextMenu{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[ValidateSet('openPowerShellHere','editWithPowerShellISE')]
$contextType,
$platform='x64',
[switch]$noProfile,
[switch]$asAdmin
)
@DBremen
DBremen / ConvertTo-ISEAddOn.ps1
Last active August 16, 2022 00:47
PowerShell function to create integrated ISE-AddOns based James Brundages original version
´#based on function from James Brundage
function ConvertTo-ISEAddOn{
[CmdletBinding(DefaultParameterSetName="CreateOnly")]
param(
[Parameter(Mandatory=$true,
ParameterSetName="DisplayNow")]
[string]$DisplayName,
[Parameter(Mandatory=$true,
ParameterSetName="CreateOnly")]
@DBremen
DBremen / Expand-Alias.ps1
Last active August 16, 2022 00:45
PowerShell function to expand aliases for ISE and files
function Expand-Alias{
[CmdletBinding(DefaultParameterSetName = 'Text')]
param(
[Parameter(Mandatory=$false, Position=0, ParameterSetName = 'Text')]
$code = $psISE.CurrentFile.Editor.Text,
[Parameter(Mandatory=$true, ParameterSetName = 'Path')]
[ValidateScript({
if (-not (Test-Path -PathType Leaf -LiteralPath $_ )) {
throw "Path '$_' does not exist. Please provide the path to an existing File."
}
@DBremen
DBremen / Show-MyCommand.ps1
Last active August 16, 2022 00:47
Show-Command for custom functions
function Out-Stuff{
[CmdletBinding(DefaultParameterSetName='Basic')]
param(
[Parameter(Mandatory)]
[ValidateSet('choice1','choice2','choice3')]
$myChoice,
[Parameter(ParameterSetName='Basic')]
$text,
[Parameter(ParameterSetName='Advanced')]
[switch]$switch1,
@DBremen
DBremen / Get-FileSize.ps1
Last active March 16, 2017 12:46
Convert file size units based on the number of bytes in a file
filter Get-FileSize {
"{0:N2} {1}" -f $(
if ($_ -lt 1kb) { $_, 'Bytes' }
elseif ($_ -lt 1mb) { ($_/1kb), 'KB' }
elseif ($_ -lt 1gb) { ($_/1mb), 'MB' }
elseif ($_ -lt 1tb) { ($_/1gb), 'GB' }
elseif ($_ -lt 1pb) { ($_/1tb), 'TB' }
else { ($_/1pb), 'PB' }
)
}
@DBremen
DBremen / Get-FileInvokeWebRequest.ps1
Last active October 21, 2015 08:44
Download files using Invoke-WebRequest
function Get-FileInvokeWebRequest{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)
$start = Get-Date
Invoke-WebRequest $url -OutFile $destination
@DBremen
DBremen / Get-FileVB.ps1
Last active August 16, 2022 03:27
Download files using the DownloadFile method of the Network class within the Microsoft.VisualBasic.Devices Namespace
function Get-FileVB{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
Add-Type -AssemblyName Microsoft.VisualBasic
#resolve potential redirect
@DBremen
DBremen / Get-FileWCSynchronous.ps1
Last active August 16, 2022 03:26
Download files using the DownloadFile method of the WebClient class within the System.Net Namespace
function Get-FileWCSynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$destination = Join-Path $destinationFolder ($url | Split-Path -Leaf)