NAME
Import-IseSnippet
SYNOPSIS
Imports ISE snippets into the current sessionSYNTAX
Import-IseSnippet [-Path]
[-Recurse] [ ] Import-IseSnippet [-Recurse] -Module
[-ListAvailable] [ ] DESCRIPTION
The Import-IseSnippet cmdlet imports reusable text "snippets" from a module or a directory into the current
session. The snippets are immediately available for use in Windows PowerShell ISE. This cmdlet works only in Windows PowerShellr Integrated Scripting Environment (ISE). To view and use the imported snippets, from the Windows PowerShell ISE Edit menu, click Start Snippets or press Ctrl + J. Imported snippets are available only in the current session. To import the snippets into all Windows PowerShellISE sessions, add an Import-IseSnippet command to your Windows PowerShell profile or copy the snippet files to
your local snippets directory ($home\Documents\WindowsPowershell\Snippets).
To import snippets, they must be properly formatted in the snippet XML for Windows PowerShell ISE snippets andsaved in Snippet.ps1xml files. To create eligible snippets, use the New-IseSnippet cmdlet. New-IseSnippet creates
a
copy the snippets to the Snippets directory of a Windows PowerShell module, or to any other directory..Snippets.ps1xml file in the $home\Documents\WindowsPowerShell\Snippets directory. You can move or The Get-IseSnippet cmdlet, which gets user-created snippets in the local snippets directory, does not get imported
snippets. This cmdlet was introduced in Windows PowerShell 3.0.PARAMETERS
-Path
Specifies the path to the snippets directory in which this cmdlet imports snippets. Required? true Position? 1 Default value None Accept pipeline input? False Accept wildcard characters? false-Recurse [
Indicate that this cmdlet imports snippets from all subdirectories of the value of the Path parameter. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false] -Module
Specifies the module into the current session that this cmdlet imports snippets from. This parameter imports snippets from Snippet.ps1xml files in the Snippets subdirectory in the module path,such as $home\Documents\WindowsPowerShell\Modules\
This parameter is designed to be used by module authors in a startup script, such as a script specified in the ScriptsToProcess key of a module manifest. Snippets in a module are not automatically imported with the\Snippets. module, but you can use an Import-IseSnippet command to import them.
Required? true Position? named Default value None Accept pipeline input? False Accept wildcard characters? false-ListAvailable [
Indicates that this cmdlet gets snippets from modules that are installed on the computer, even if the modules are not imported into the current session. If this parameter is omitted, and the module that is specified by the Module parameter is not imported into the current session, the attempt to get the snippets from the module will fail. This parameter is valid only when the Module parameter is used in the command. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false] This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS
None This cmdlet does not take input from the pipeline.OUTPUTS
None This cmdlet does not generate output.NOTES
You cannot use the Get-IseSnippet cmdlet to get imported snippets. Get-IseSnippet * gets only snippets in the
$home\Documents\WindowsPowerShell\Snippets directory. Import-IseSnippet uses the Load static method of
Microsoft.PowerShell.Host.ISE.ISESnippetCollection objects. You can also use the Load * method of snippets in
the Windows PowerShell ISE object model: $psISE.CurrentPowerShellTab.Snippets.Load() The New-IseSnippet cmdlet
stores new user-created snippets in unsigned .ps1xml files. As such, Windows PowerShelll cannot load them into
a session in which the execution policy is AllSigned or Restricted . In a Restricted or AllSigned * session,
you can create, get, and import unsigned user-created snippets, but you cannot use them in the session.
To use unsigned user-created snippets that the Import-IseSnippet cmdlet returns, change the execution policy,
and then restart Windows PowerShell ISE. For more information about Windows PowerShell execution policies, see about_Execution_Policies.Example 1: Import snippets from a directory
PS C:\>Import-IseSnippet -Path "\\Server01\Public\Snippets" -Recurse
This command imports the snippets from the \Server01\Public\Snippets directory into the current session. It uses the Recurse parameter to get snippets from all subdirectories of the Snippets directory.Example 2: Import snippets from a module
PS C:\>Import-IseSnippet -Module "SnippetModule" -ListAvailable
This command imports the snippets from the SnippetModule module. The command uses the ListAvailable parameter to import the snippets even if the SnippetModule module is not imported into the user's session when the command runs.Example 3: Find snippets in modules
PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction
SilentlyContinue} | foreach {$_.fullname}
This command gets snippets in all installed modules in the PSModulePath environment variable.Example 4: Import all module snippets
PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction
SilentlyContinue} | foreach {$psise.CurrentPowerShellTab.Snippets.Load($_)}
This command imports all snippets from all installed modules into the current session. Typically, you don't needto run a command like this because modules that have snippets will use the Import-IseSnippet cmdlet to import them
for you when the module is imported.Example 5: Copy all module snippets
PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction
SilentlyContinue} | Copy-Item -Destination $home\Documents\WindowsPowerShell\Snippets
This command copies the snippet files from all installed modules into the Snippets directory of the current user. Unlike imported snippets, which affect only the current session, copied snippets are available in every Windows PowerShell ISE session.RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821535Get-IseSnippet
New-IseSnippet