< Back

Get-Snippet

Sun Jan 19, 2020 6:46 pm

NAME Get-Snippet



SYNOPSIS

Gets the snippets that are available on the local computer.





SYNTAX

Get-Snippet [[-Name] <String[]>] [[-ModuleName] <String>] [-NoHelp <SwitchParameter>] [-InformationAction

<ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]





DESCRIPTION

The Get-Snippet cmdlet gets the snippets that are available on the local computer.



By default, Get-Snippet returns all snippets that are available on the local computer. To return a filtered list

of snippets, you can use the Name parameter to specify the name of the snippets you want to see.





PARAMETERS

-Name <String[]>

The name of the snippet.



Required? false

Position? 0

Default value

Accept pipeline input? false

Accept wildcard characters? true



-ModuleName <String>

The name of the module where the snippet is located.



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-NoHelp [<SwitchParameter>]

Skips the lookup of Snippet help information when the snippet is retrieved. Use this parameter when you are

retrieving a snippet that you need to invoke many times and you want to cache the object for faster

performance during invocation of the snippet.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-InformationAction <ActionPreference>





Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-InformationVariable <String>





Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

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







OUTPUTS

SnippetPx.Snippet







NOTES





When retrieving snippets, it is best to provide a module name in the ModuleName parameter whenever possible.

This will result in the fastest possible performance. You can further improve performance by using the NoHelp

switch parameter to skip the lookup of the snippet help information.



When you use wildcards in the Name or ModuleName parameters, when no ModuleName parameter is provided, or when

no parameters are provided, the Get-Snippet command looks for matching snippets in the following folders in

the order in which they are listed:



- the current user snippets folder (Documents\\WindowsPowerShell\\snippets);



- the all users snippets folder (Program Files\\WindowsPowerShell\\snippets);



- the snippets folder in the module that is currently loading (if a module is loading);



- the snippets folder in the module where the cmdlet was invoked (if it was invoked from a module);



- the snippets folder in the SnippetPx module (SnippetPx\\snippets);



- the snippets folder in all other loaded modules;



- the snippets folder in all unloaded modules, in the order in which they are discovered according to the

PSModulePath environment variable;



To guarantee uniqueness of snippets across modules, snippets specific to a module should use a snippet name

prefixed with the module name. For example, a snippet to provision AD users in an ActiveDirectory module could

use the filename ActiveDirectory.User.Provision.ps1.



Using spaces in snippet filenames is supported, but discouraged.



-------------------------- Example 1 --------------------------



PS C:\\> Get-Snippet



This command gets all snippets that are available on the local system, and outputs them in the order in which they

are discovered.







-------------------------- Example 2 --------------------------



PS C:\\> Get-Snippet -Name Module.Initialize -ModuleName SnippetPx



This command gets the Module.Initialize snippet from the SnippetPx module.







-------------------------- Example 3 --------------------------



PS C:\\> Get-Snippet -Name ProxyFunction*



This command gets all snippets on the local system whose name starts with "ProxyFunction".







-------------------------- Example 4 --------------------------



PS C:\\> Get-Snippet -ModuleName SnippetPx



This command gets all snippets that are included in the SnippetPx module.









RELATED LINKS

Invoke-Snippet