Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions reference/3.0/ISE/Get-IseSnippet.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
ms.date: 06/09/2017
schema: 2.0.0
locale: en-us
Expand All @@ -7,17 +7,19 @@ online version: http://go.microsoft.com/fwlink/?LinkID=238787
external help file: ISE-help.xml
title: Get-IseSnippet
---

# Get-IseSnippet

## SYNOPSIS
Gets snippets that the user created.

## SYNTAX

```
Get-IseSnippet [<CommonParameters>]
```

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

Expand All @@ -27,26 +29,32 @@ When you use the New-IseSnippet cmdlet to create a snippet, New-IseSnippet creat
**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.

## EXAMPLES

### Example 1

```
PS C:\> Get-ISESnippet
PS> 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}
PS> 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
PS> #Parse-Snippet Function

function Parse-Snippet
{
Expand Down Expand Up @@ -78,9 +86,11 @@ 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
PS> $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.
Expand All @@ -93,22 +103,29 @@ 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.

## PARAMETERS

### CommonParameters

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

## INPUTS

## OUTPUTS

### System.IO.FileInfo

**Get-ISESnippet** returns a file object that represents the snippet file.

## NOTES
* The **New-IseSnippet** cmdlet stores new user-created snippets in unsigned .ps1xml files. As such, Windows PowerShell cannot add them to 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.

- The **New-IseSnippet** cmdlet stores new user-created snippets in unsigned .ps1xml files. As such, Windows PowerShell cannot add them to 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 **Get-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.

## RELATED LINKS

[New-IseSnippet](New-IseSnippet.md)
Expand Down
13 changes: 8 additions & 5 deletions reference/3.0/ISE/ISE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
ms.date: 06/09/2017
schema: 2.0.0
locale: en-us
Expand All @@ -9,19 +9,22 @@ Module Guid: bae93d8e-782c-4a23-b87f-8699bfc17ee0
title: ISE
Module Name: ISE
---

# ISE Module

## Description
This section contains the help topics for the cmdlets that are installed with the Windows PowerShell ISE module. The ISE module contains cmdlets that add features to Windows PowerShell Integrated Scripting Environment (ISE).

## ISE Cmdlets
### [Get-IseSnippet](Get-IseSnippet.md)

### Get-IseSnippet.md
Gets snippets that the user created.


### [Import-IseSnippet](Import-IseSnippet.md)
### Import-IseSnippet.md

Imports ISE snippets into the current session


### [New-IseSnippet](New-IseSnippet.md)
### New-IseSnippet.md

Creates a Windows PowerShell ISE code snippet.
49 changes: 38 additions & 11 deletions reference/3.0/ISE/Import-IseSnippet.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
ms.date: 06/09/2017
schema: 2.0.0
locale: en-us
Expand All @@ -7,23 +7,27 @@ online version: http://go.microsoft.com/fwlink/?LinkID=242050
external help file: ISE-help.xml
title: Import-IseSnippet
---

# Import-IseSnippet

## SYNOPSIS
Imports ISE snippets into the current session

## SYNTAX

### FromFolder (Default)

```
Import-IseSnippet [-Path] <String> [-Recurse] [<CommonParameters>]
```

### FromModule

```
Import-IseSnippet [-Recurse] -Module <String> [-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).
Expand All @@ -41,45 +45,57 @@ You can move or copy the snippets to the Snippets directory of a Windows PowerSh
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.

## EXAMPLES

### Example 1: Import snippets from a directory

```
PS C:\> Import-IseSnippet -Path \\Server01\Public\Snippets -Recurse
PS> 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
PS> 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}
PS> ($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($_)}
PS> ($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 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.

### 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
PS> ($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.

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

Expand All @@ -98,6 +114,7 @@ Accept wildcard characters: False
```

### -Module

Imports snippets from the specified module into the current session.
Wildcard characters are not supported.

Expand All @@ -119,6 +136,7 @@ Accept wildcard characters: False
```

### -Path

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

Expand All @@ -135,6 +153,7 @@ Accept wildcard characters: True
```

### -Recurse

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

```yaml
Expand All @@ -150,25 +169,33 @@ Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://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 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.

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

## RELATED LINKS

[Get-IseSnippet](Get-IseSnippet.md)

[New-IseSnippet](New-IseSnippet.md)
[New-IseSnippet](New-IseSnippet.md)
Loading