Skip to content

Instantly share code, notes, and snippets.

@lipkau
Created September 8, 2015 06:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lipkau/dde7903a3c6024746d0c to your computer and use it in GitHub Desktop.
Save lipkau/dde7903a3c6024746d0c to your computer and use it in GitHub Desktop.
[PowerShell] Snippet: My Sublime Text 3 PowerShell Snippets
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[\$($1)]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>sub</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[@(
${1}
)
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>arr</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[Start-Job -Name ${1:myJob} -InitializationScript {${2:Import-Module BitsTransfer}} -FilePath ${3:myFile.ps1}]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>bgjobscript</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[begin {$1}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>beg</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[catch ${1:[Exception]}
{
$2
}
$0]]></content>
<tabTrigger>catch</tabTrigger>
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[\$ChoiceOptions = @(${1:1,2,3})
\$DefaultChoice = 0
\$ChoiceDescription = New-Object System.Collections.ObjectModel.Collection[System.Management.Automation.Host.ChoiceDescription]
\$ChoiceOptions | foreach \{
\$ChoiceDescription.Add(
(New-Object "System.Management.Automation.Host.ChoiceDescription" -ArgumentList \$_)
)
\}
\$Host.ui.PromptForChoice(${2:"Caption"}, ${3:"message"}, \$ChoiceDescription, \$DefaultChoice)
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>choice</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[[CmdletBinding(${1})]
[OutputType(${2})]
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>cmdbind</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[<#
${1}
#>
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>comm</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
<!-- Optional: Description to show in the menu -->
<description>Comment block</description>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[\$tmpFile = [IO.Path]::GetTempFileName()
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>tmp</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[${1:\$Script:ScriptDir = Split-Path \$MyInvocation.MyCommand.Path -Parent
${2:\$Script:ScriptDir = split-path -parent \$PSCommandPath}
$0]]></content>
<tabTrigger>thisdir</tabTrigger>
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[do
{
${1}
} until (${2:\$i -eq \$true})
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dountil</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[do
{
${1}
} while (${2:\$true})
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dowhile</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[<#
.SYNOPSIS
${1:Lorem ipsum}
.DESCRIPTION
${2:Lorem ipsum dolor sit amet}
.INPUTS
${3:string}
.OUTPUTS
${4:bool}
.EXAMPLE
c:\> Set-Foo "Hello World"
---------
Example 1
.EXAMPLE
c:\> Set-Foo "Hello World" 10
---------
Example 2
#>
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>docblock</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[else {$1}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>else</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[elseif ($1) {$2}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>elif</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[set-psdebug ${1:-${2:Step}}
$0]]></content>
<tabTrigger>sd</tabTrigger>
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[end {$1}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>end</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[filter ${1:filterName}
{
$2
}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>fil</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[finally
{
$1
}
$0]]></content>
<tabTrigger>fin</tabTrigger>
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[for ($i=${1:0}; $i ${2:-lt 10}; $i++)
{
${3}
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>for</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[foreach (${1:\$item} in ${2:\$collection})
{
${3}
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>foreach</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[function ${1:funcName}
{
$2
}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>fun</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[@{
${1:key} = ${2:"value"}
${3:key} = ${4:0}
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dict</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[@"
$1
"@
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>hhere</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[@'
$1
'@
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>here</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[if ($1)
{
$2
}
else
{
$3
}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>ifelse</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[if ($1) {$2}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>if</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[#[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
if([System.Windows.Forms.MessageBox]::Show(${1:"Question", ${2:"Caption"},[System.Windows.Forms.MessageBoxButtons]::YesNo) -eq "Yes")
{
$3
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>MsgBoxYesNo</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[#[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][System.Windows.Forms.MessageBox]::Show(${1:Text,${2:Caption)
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>MsgBox</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[filter ${1:filterName}
{
$2
}]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>fil</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[New-Object PSObject -Property @{
${1:property} = ${2:"value"}
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>psobject</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[param
(
$1
${2:\$InputObject}
)
$0]]></content>
<tabTrigger>param</tabTrigger>
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[${1:\$MyDocs} = [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments)
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>mydocs</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[process {$1}
$0]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>proc</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[function ${1} {
<#
For more information about proxy functions, see the following article on the
Microsoft PowerShell Team blog:
http://blogs.msdn.com/powershell/archive/2009/01/04/extending-and-or-modifing-commands-with-proxies.aspx
#>
<#
To create a proxy function for the $Name$ cmdlet, paste the results of the following command into the body of this function and then remove this comment:
[Management.Automation.ProxyCommand]::Create((New-Object Management.Automation.CommandMetaData (Get-Command $Name$)))
#>
}]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>proxyfunction</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[#requires -pssnapin $0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>reqs</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[#requires -version ${0:2}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>reqv</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[#requires -$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>req</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[$emailParameter = @{
From = ${1:"user@domain.com"}
To = ${2:"user1@domain.com, User2 <user2@domain.com>"}
Subject = ${3:"Notice of script failure"}
Body = ${4:"The following script failed..."}
SmtpServer = ${5:"smtp.domain.com"}
Credential = ${6:"domain01\admin01"}
}
Send-MailMessage @emailParameter
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>Send-Email</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<snippet>
<content><![CDATA[switch (${1:\$x})
{
${2:"value"} \{
${3:break}
\}
{\$_ -in 'A','B','C'} {}
Default {}
}
$0]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>switch</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.powershell</scope>
</snippet>
<!-- See http://www.sublimetext.com/docs/snippets for more information -->
<snippet>
<content><![CDATA[try
{
$1
}
$0]]></content>
<tabTrigger>try</tabTrigger>
<scope>source.powershell</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment