Skip to content

Instantly share code, notes, and snippets.

@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 / Clear-Clipboard.ps1
Last active August 16, 2022 00:47
Function to identify and stop/restart process blocking the clipboard
function Restart-Process{
[CmdletBinding()]
param([Parameter(ValueFromPipeline = $true)] $process)
Begin{
$selectedIndex=$multiInstanceName=$null
}
Process{
if ($multiInstanceName -eq $_.Name){continue}
$procToRestart=$_
#handle if there are multiple instances of the same application
@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 / CleanData_CrossJoin.vb
Last active August 16, 2022 00:46
VBA Excel to cross-join and clean data with multiple entries per cell separated by comma or line-breaks
Private Function isSaved() As Boolean
Dim lastSaved As String
On Error GoTo EHandler
s = ActiveWorkbook.BuiltinDocumentProperties("last save time")
isSaved = True
Exit Function
EHandler:
isSaved = False
End Function
@DBremen
DBremen / Get-TextWithin.ps1
Created February 8, 2021 17:09
PowerShell function to extract text between delimiters
function Get-TextWithin {
<#
.SYNOPSIS
Get the text between two surrounding characters (e.g. brackets, quotes, or custom characters)
.DESCRIPTION
Use RegEx to retrieve the text within enclosing characters.
.PARAMETER Text
The text to retrieve the matches from.
.PARAMETER WithinChar
Single character, indicating the surrounding characters to retrieve the enclosing text for.
@DBremen
DBremen / ConvertFrom-ExcelClipboard.ps1
Last active August 16, 2022 00:46
Convert copied range from excel to an array of PSObjects
function ConvertFrom-ExcelClipboard {
<#
.SYNOPSIS
Convert copied range from excel to an array of PSObjects
.DESCRIPTION
A range of cells copied into the clipboard is converted into PSObject taking the first row (or provided property names via Header parameter) as the properties.
.EXAMPLE
#Considering a range of cells including header has been copied to the clipboard
ConvertFrom-ExcelClipboard
.EXAMPLE
@DBremen
DBremen / ISECodeTemplate.ps1
Created August 24, 2015 14:55
Create default code template for PowerShell ISE
function Edit-ISETemplate{
$ISETemplatePath = "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowerShell\ISETemplate.ps1"
if (!Test-Path){
New-Item $ISETemplatePath -ItemType File
}
psedit "$ISETemplatePath"
}
Register-ObjectEvent $psise.CurrentPowerShellTab.Files CollectionChanged -Action {
# files collection
@DBremen
DBremen / Get-FileWCAsynchronous.ps1
Last active August 16, 2022 00:45
Download files using the DownloadFileAsync method of the WebClient class within the System.Net Namespace
function Get-FileWCAsynchronous{
param(
[Parameter(Mandatory=$true)]
$url,
$destinationFolder="$env:USERPROFILE\Downloads",
[switch]$includeStats
)
$wc = New-Object Net.WebClient
$wc.UseDefaultCredentials = $true
$file = $url | Split-Path -Leaf
@DBremen
DBremen / WMIProxyCommands.ps1
Created November 13, 2015 14:25
Proxy commands for Get-WmiObject and Get-CimInstance that support PowerShell query syntax via 'PowerShellFilter' paramater
foreach ($command in ('Get-WmiObject','Get-CimInstance')){
$Metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command $command)
$proxyCmd = [System.Management.Automation.ProxyCommand]::Create($Metadata) #| clip
if ($command -eq 'Get-WmiObject'){
$newParam = @'
[Parameter(ParameterSetName='query')]
[ScriptBlock]
$PowerShellFilter,
'@
}
@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."
}