PowerShell Logo Small

Get-IseSnippet



This is the built-in help made by Microsoft for the command 'Get-IseSnippet', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Gets snippets that the user created.

SYNTAX


Get-IseSnippet [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Get-ISESnippet cmdlet gets the PS1XML files that contain reusable text "snippets" that the user created. It works only in Windows PowerShell ISE.


When you use the New-IseSnippet cmdlet to create a snippet, New-IseSnippet creates a <SnippetTitle>.Snippets.ps1xml file in the $home\Documents\WindowsPowerShell\Snippets
directory. Get-ISESnippet gets the snippet files in the Snippets directory.


Get-IseSnippet does not get built-in snippets or snippets that are imported from modules by using the Import-IseSnippet cmdlet.


This cmdlet is introduced in Windows PowerShell 3.0.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=287355
New-IseSnippet
Import-IseSnippet

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>Get-ISESnippet



This command gets all user-define snippets in the Snippets directory.




-------------------------- EXAMPLE 2 --------------------------

PS C:\>Invoke-Command -Computer (Get-Content Servers.txt) {Get-ISESnippet | Copy-Item -Destination \\Server01\Share01\Snippets}



This command copies all of the user-created snippets from a group of remote computers to a shared Snippets directory.

The command uses the Invoke-Command cmdlet to run a Get-ISESnippet command on the computers in the Servers.txt file. A pipeline operator (|) sends the snippet files to the
Copy-Item cmdlet, which copies them to the directory that is specified by the Destination parameter.




-------------------------- EXAMPLE 3 --------------------------

PS C:\>#Parse-Snippet Function

function Parse-Snippet
{
$a = Get-ISESnippet
$snippetNamespace = @{x="http://schemas.microsoft.com/PowerShell/Snippets"}
foreach ($snippetFile in $a)
{
Write-Host ""
$Title = Select-Xml -Path $snippetFile.FullName -Namespace $snippetNamespace -XPath "//x:Title" | foreach {$_.Node.InnerXML}
$Text = Select-Xml -Path $snippetFile.FullName -Namespace $snippetNamespace -XPath "//x:Script" | foreach {$_.Node.InnerText}
Write-Host "Title: $Title"
Write-Host "Text: $Text"
}
}

# Sample Output

Title: Mandatory
Text:
Param
(
[parameter(Mandatory=True)]
[String[]]
$<ParameterName>
)

Title: Copyright
Text: (c) Fabrikam, Inc. 2012



This function uses the Get-ISESnippet and Select-Xml cmdlets to display the Title and Text of each snippet on the local computer.




-------------------------- EXAMPLE 4 --------------------------

PS C:\>$psISE.CurrentPowerShellTab.Snippets | Format-Table DisplayTitle, Description



This command displays the title and description of all snippets in the session, including built-in snippets, user-defined snippets, and imported snippets.

The command uses the Windows PowerShell ISE object model. The $psISE variable represents the Windows PowerShell ISE host program. The CurrentPowerShellTab property of $psISE
represent the current session. The Snippets property represents snippets in the current session.

The $psISE.CurrentPowerShellTab.Snippets command returns a Microsoft.PowerShell.Host.ISE.ISESnippet object that represents a snippet, unlike the Get-IseSnippet cmdlet,
which returns a file object (System.Io.FileInfo) that represents a snippet file.

The command also uses the Format-Table cmdlet to display the DisplayTitle and Description properties of the snippets in a table.