Import-IseSnippet
Imports ISE snippets into the current session
Syntax
FromFolder (Default)
Import-IseSnippet
[-Path] <String>
[-Recurse]
[<CommonParameters>]
FromModule
Import-IseSnippet
-Module <String>
[-Recurse]
[-ListAvailable]
[<CommonParameters>]
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 PowerShell 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
PowerShell ISE 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 and saved in Snippet.ps1xml files. To create eligible snippets, use the New-IseSnippet
cmdlet. New-IseSnippet creates a <SnippetTitle>.Snippets.ps1xml file in the
$HOME\Documents\WindowsPowerShell\Snippets directory. You can move or copy the snippets to the
Snippets directory of a Windows PowerShell module, or to any other directory.
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.
Examples
Example 1: Import snippets from a directory
This example 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.
Import-IseSnippet -Path \\Server01\Public\Snippets -Recurse
Example 2: Import snippets from a module
This example 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.
Import-IseSnippet -Module SnippetModule -ListAvailable
Example 3: Find snippets in modules
This example gets snippets in all installed modules in the PSModulePath environment variable.
($Env:PSModulePath).Split(";") |
ForEach-Object {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} |
ForEach-Object {$_.FullName}
Example 4: Import all module snippets
This example imports all snippets from all installed modules into the current session. Typically,
you don't need to 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.
($Env:PSModulePath).Split(";") |
ForEach-Object {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} |
ForEach-Object {$psISE.CurrentPowerShellTab.Snippets.Load($_)}
Example 5: Copy all module snippets
This example 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.
($Env:PSModulePath).Split(";") |
ForEach-Object {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} |
Copy-Item -Destination $HOME\Documents\WindowsPowerShell\Snippets
Parameters
-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 fails.
This parameter is valid only when the Module parameter is used in the command.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
FromModule
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Module
Imports snippets from the specified module into the current session. Wildcard characters are not supported.
This parameter imports snippets from Snippet.ps1xml files in the Snippets subdirectory in the
module path, such as $HOME\Documents\WindowsPowerShell\Modules\<ModuleName>\Snippets.
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 module, but you can use an Import-IseSnippet command to import
them.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
FromModule
| Position: | Named |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Path
Specifies the path to the snippets directory in which this cmdlet imports snippets.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | True |
| DontShow: | False |
Parameter sets
FromFolder
| Position: | 1 |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-Recurse
Indicates that this cmdlet imports snippets from all subdirectories of the value of the Path parameter.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
None
You can't pipe objects to this cmdlet.
Outputs
None
This cmdlet returns no output.
Notes
You cannot use the
Get-IseSnippetcmdlet to get imported snippets.Get-IseSnippetgets only snippets in the$HOME\Documents\WindowsPowerShell\Snippetsdirectory.Import-IseSnippetuses 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-IseSnippetcmdlet stores new user-created snippets in unsigned.ps1xmlfiles. As such, Windows PowerShell 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-IseSnippetcmdlet returns, change the execution policy, and then restart Windows PowerShell ISE.For more information about Windows PowerShell execution policies, see about_Execution_Policies.