PowerShell Snippets A Great Learning Tool

When I talk to people about Powershell they often ask how can they easily learn the syntax. Here’s a good tip

Open PowerShell ISE and press CTRL + J

image

You will find a number of snippets that will enable you to write your scripts easily.  Johnathan Medd PowerShell MVP has written a good post about snippets on the Hey, Scripting Guy! blog so I will not repeat that but suggest that you go and read that post. It will show you how quickly and easily you will be able to write more complex Powershell scripts as you do not have to learn the syntax but can use the snippets to insert all the code samples you require.

Not only are there default snippets for you to use but you can create your own snippets. However there isn’t a snippet for creating a new snippet so here is the code to do that

I frequently use the SQL Server SMO Object in my code so I created this snippet

I also use Data Tables a lot so I created a snippet for that too

Denniver Reining has created a Snippet Manager which you can use to further expand your snippets usage and it is free as well.

If you have further examples of useful snippets please feel free to post them in the comments below

Edit 16/12/2014

I am proud that this article was nominated for the Tribal Awards. Please go and vote for your winners in all the categories

http://www.sqlservercentral.com/articles/Awards/119953/

Personally in the article category I will be voting for

Gail Shaw’s SQL Server Howlers

7 thoughts on “PowerShell Snippets A Great Learning Tool

  1. Pingback: (SFTW) SQL Server Links 12/09/14 - John Sansom

  2. Pingback: BPOTW 2014-10-12 | SQL Notes From The Underground

  3. Pingback: Useful PowerShell ISE Snippets « FoxDeploy.com

  4. Pingback: Tribal Awards 2014 Finalists – Simple-Talk

  5. Pingback: Populating My DBA Database for Power Bi with PowerShell – Databases | SQL DBA with A Beard

  6. Pingback: Quickly Creating Test Users in SQL Server with PowerShell using the sqlserver module and dbatools | SQL DBA with A Beard

Please feel free to comment on this post. All comments are moderated first before appearing on the site