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
´#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")] |
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 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 |
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 Out-Stuff{ | |
[CmdletBinding(DefaultParameterSetName='Basic')] | |
param( | |
[Parameter(Mandatory)] | |
[ValidateSet('choice1','choice2','choice3')] | |
$myChoice, | |
[Parameter(ParameterSetName='Basic')] | |
$text, | |
[Parameter(ParameterSetName='Advanced')] | |
[switch]$switch1, |
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
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 |
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-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. |
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 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 |
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 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 |
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-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 |
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
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, | |
'@ | |
} |
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 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." | |
} |