CmdID / PowerShell / Cmdlets / Get
Get-IseSnippet
Gets snippets that the user created. PowerShell reference
From the PowerShell reference
What it does
Gets snippets that the user created. The Get-IseSnippet cmdlet gets the PS1XML files that contain reusable text snippets that the user created. It works only in Windows PowerShell Integrated Scripting Environment (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. This cmdlet does not get built-in snippets or snippets that are imported from modules through the Import-IseSnippet cmdlet. This cmdlet was introduced in Windows PowerShell 3.0.
Get-IseSnippet [<CommonParameters>]
Get all user-defined snippets
Get-IseSnippetIdentifyCopy all user-defined snippets from remote computers to a shared directory
Invoke-Command -Computer (Get-Content Servers.txt) -ScriptBlock {
Get-IseSnippet | Copy-Item -Destination \\Server01\Share01\Snippets
}IdentifyDisplay the title and text of each snippet on a local computer
#Parse-Snippet Function
function Parse-Snippet {
$SnippetFiles = Get-IseSnippet
$SnippetNamespace = @{x="http://schemas.microsoft.com/PowerShell/Snippets"}
foreach ($SnippetFile in $SnippetFiles) {
Write-Host ""
$Title = Select-Xml -Path $SnippetFile.FullName -Namespace $SnippetNamespace -XPath "//x:Title" |
ForEach-Object {$_.Node.InnerXml}
$Text = Select-Xml -Path $SnippetFile.FullName -Namespace $SnippetNamespace -XPath "//x:Script" |
ForEach-Object {$_.Node.InnerText}
Write-Host "Title: $Title"
Write-Host "Text: $Text"
}
}IdentifyDisplay the title and description of all snippets in the session
$psISE.CurrentPowerShellTab.Snippets | Format-Table DisplayTitle, DescriptionIdentifyIts page in the reference: Get-IseSnippet.