My personal PowerShell ISE snippets

Following the post of Josh RICKARD on 4SysOps about ISE snippets,
I just wanted to share two of my personal snippets I use very often as a System Administrator.

Foreach function with a server list from an array

$SnippetText = @'
$ServerList=@(
'Server1'
'Server2'
)
foreach($Server in $ServerList)
{

}
'@

$NewSnippetParams = @{
    Title       = 'Foreach with server list from array'
    Description = 'Foreach function using an array of servers'
    Text        = $SnippetText
    CaretOffset = 17
    Author      = 'Luc FULLENWARTH'
}

New-IseSnippet @NewSnippetParams

Foreach function with a server list imported from an file

$SnippetText = @'
$ServerList = Get-Content -Path C:\Temp\MyList.txt
foreach ($Server in $ServerList)
{

}
'@

$NewSnippetParams = @{
    Title       = 'Foreach with server list from file'
    Description = 'Foreach function using a file to get the server list'
    Text        = $SnippetText
    CaretOffset = 33
    Author      = 'Luc FULLENWARTH'
}

New-IseSnippet @NewSnippetParams

Help section

$SnippetText = @'
 extension -name "File"
File.txt

.EXAMPLE

C:\PS> extension -name "File" -extension "doc"
File.doc

.EXAMPLE

C:\PS> extension "File" "doc"
File.doc

.LINK

http://www.fabrikam.com/extension.html

.LINK

Set-Item
#>
'@

$NewSnippetParams = @{
    Title       = 'Help section'
    Description = 'Creates a Help section with the most common sections'
    Text        = $SnippetText
    CaretOffset = 14
    Author      = 'Luc FULLENWARTH'
}

New-IseSnippet @NewSnippetParams

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s