Skip to main content

Built-in Snippets

Built-in Snippets provides predefined PowerShell structures and commands that you can insert directly into your script.

Built-in Snippets in Master Wrapper

Available snippets

SnippetPrefixDescription
Comment Blockblock-commentInserts a multi-line comment block.
do-untildo-untilRepeats a statement list until a condition is met.
do-whiledo-whileRepeats a statement list while a condition is met.
elseelseDefines what runs when all if and elseif conditions are false.
elseifelseifAdds an alternative path when an if condition is false.
EnumenumCreates a distinct type made up of named labels.
forforCreates a loop that runs while a condition evaluates to true.
for-reversedforrCreates a reversed for loop.
foreachforeachIterates through a collection with a named variable.
foreach-itemforeach-itemQuickly inserts a foreach item definition after you highlight the collection variable and press Tab.
HashtablehashtableCreates a key/value store for efficient data retrieval.
Here-StringhsInserts a here-string that escapes text but still evaluates variables.
Here-String (Literal)hslInserts a literal here-string that escapes all text exactly as written.
ififRuns code when a conditional test evaluates to true.
PSCustomObjectpscustomobjectCreates a custom object from a hashtable.
Region BlockregionInserts a region block for organizing and folding code.
splatsplatUses a hashtable to pass parameters concisely.
switchswitchProvides an alternative to a series of if statements.
try-catchtry-catchRuns a code block and handles terminating exceptions.
try-catch-finallytry-catch-finallyRuns code with exception handling and a cleanup block.
try-finallytry-finallyRuns code and performs cleanup regardless of the outcome.
whilewhileRepeats an action while a condition is true.