Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Import-IseSnippet

Updated: October 17, 2013

Applies To: Windows PowerShell 4.0

Import-IseSnippet

Imports ISE snippets into the current session

Syntax

Parameter Set: FromFolder
Import-IseSnippet [-Path] <String> [-Recurse] [ <CommonParameters>]

Parameter Set: FromModule
Import-IseSnippet -Module <String> [-ListAvailable] [-Recurse] [ <CommonParameters>]




Detailed 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 ISEEdit 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 be imported, the snippets 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.

NOTE: The Get-IseSnippet cmdlet, which gets user-created snippets in the local snippets directory, does not get imported snippets.

This cmdlet is introduced in Windows PowerShell 3.0.

Parameters

-ListAvailable

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Module<String>

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.


Aliases

none

Required?

true

Position?

named

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String>

Imports snippets from the specified file system directory. Wildcards characters are supported.


Aliases

none

Required?

true

Position?

1

Default Value

None

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Recurse

Imports snippets from all subdirectories of the value of the Path parameter.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    This cmdlet does not take input from the pipeline.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • 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 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-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.

Examples

Example 1: Import snippets from a directory

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.


PS C:\> Import-IseSnippet -Path \\Server01\Public\Snippets -Recurse

Example 2: Import snippets from a module

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.


PS C:\> Import-IseSnippet -Module SnippetModule -ListAvailable

Example 3: Find snippets in modules

This command gets snippets in all installed modules in the PSModulePath environment variable.


PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} | foreach {$_.fullname}

Example 4: Import all module snippets

This command 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.


PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} | foreach {$psise.CurrentPowerShellTab.Snippets.Load($_)}

Example 5: Copy all module 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.


PS C:\> ($env:PSModulePath).split(";") | foreach {dir $_\*\Snippets\*.Snippets.ps1xml -ErrorAction SilentlyContinue} | Copy-Item -Destination $home\Documents\WindowsPowerShell\Snippets

Related topics



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.