Search
Generic filters
Exact matches only
Filter by Custom Post Type

Walkthrough: An example of how I write PowerShell functions

A couple of days ago I posted a blog article titled "PowerShell function: Test-ConsoleColor provides a visual demonstration of the foreach scripting construct" and today I thought I would walk you through that function step by step since it's what I consider to be a well written PowerShell function.

It starts out by using the #Requires statement to require at least PowerShell version 3 or it won't run. It also requires that the PowerShell Community Extensions module be installed since it uses a function from that module and continuing without it only leads to errors:

#Requires -Version 3.0 -Modules Pscx

The function is then declared using a Pascal case name that uses an approved verb along with a singular noun. Comment based help is provided just inside the function declaration. This isn't the only location where comment based help can be specified at, but it's my preferred location for it.

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

Mississippi PowerShell User Group Virtual Meeting – June 9th 2015

Uncategorized
Jun 8, 2015
0

Join us virtually on Tuesday, June 9th at 8:30pm Central Time when PowerShell MVP Trevor Sullivan will present “Creating Object-Oriented Scripts using PowerShell Classes”.

During this deep, technical discussion, we will take a look at PowerShell classes, and then authoring PowerShell Desired State Configuration (DSC) Resource using PowerShell v5 classes. We’ll also explore leveraging PowerShell DSC on Microsoft Azure infrastructure (IaaS) virtual machines using the Azure VM DSC Extension. This session assumes some previous knowledge of PowerShell & DSC, so make sure you’re familiar with the basics ahead of time!

About Trevor

Trevor Sullivan is an 11 year veteran in the IT industry, and a multi-year recipient of the Microsoft Most Valuable Professional (MVP) award for Windows PowerShell automation. With 8 years of automation experience with PowerShell, and 3 years of experience working with the Microsoft Azure public cloud, Trevor is uniquely equipped to offer cost and process efficiency enhancements to nearly any area of the business. Trevor is a passionate community member, and seeks to spread awareness and knowledge about various technical solutions to business problems through a variety of social media channels. You can find out more about Trevor at http://trevorsullivan.net and http://twitter.com/pcgeek86.

Register via EventBrite to receive the URL for this virtual meeting. Click here to be redirected to the original post of this article on the Mississippi PowerShell User Group website which contains additional information about the meeting including the system requirements to attend.

µ

Mississippi PowerShell User Group Virtual Meeting - May 12th 2015

Uncategorized
May 11, 2015
0

Join us virtually on Tuesday, May 12th at 8:30pm Central Time when PowerShell MVP Kirk Munro will present "A peek inside the Poshoholic’s toolbelt".

It’s easy to get excited about all of the new technologies that are being talked about these days.  PowerShell 5.  Windows 10.  Nano server.  .NET Core.  But none of these technologies have been released yet, and even when they are released, it will be some time before we can fully adopt them in our organizations.  That’s why I like to arm my PowerShell toolbelt with impactful modules that work with current releases, so that people like you and I can work with innovative solutions for today while we keep learning about what will be available tomorrow.  This session is about those modules that I use in my toolbelt every day.  HistoryPx, FormatPx, DebugPx, SnippetPx, TypePx, and others.  Highly impactful, innovative PowerShell solutions that you can use, right now.

About Kirk
Kirk Munro is a Technical Product Manager at Provance Technologies, where he is helping build the next generation of Provance’s flagship IT Asset Management product, along with several smaller products such as the ScsmPx PowerShell module and the Auto-Close Work Item MP.  He is also an 8-time recipient of the Microsoft Most Valued Professional (MVP) award for his involvement in the PowerShell community.  For the past 9 years, Kirk has focused almost all of his time on PowerShell and PowerShell solutions, including managing popular products such as PowerGUI, PowerWF and PowerSE.  It is through this work he became known as the world’s first self-proclaimed Poshoholic.  Outside of work these days Kirk is returning to his software developer roots, learning mobile technologies like Xamarin and Ruby on Rails, and taking courses on Coursera or edX whenever he can make the time to do so.

Register via EventBrite to receive the URL for this virtual meeting. Click here to be redirected to the original post of this article on the Mississippi PowerShell User Group website which contains additional information about the meeting including the system requirements to attend.

µ

PowerShell Tip from the Head Coach of the 2014 Winter Scripting Games: Design for Performance and Efficiency!

There are several concepts that come to mind when discussing the topic of designing your PowerShell commands for performance and efficiency, but in my opinion one of the items at the top of the list is "Filtering Left" which is what I'll be covering in this blog article.

First, let's start out by taking a look at an example of a simple one-liner command that's poorly written from a performance and efficiency standpoint:

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

PowerShell Tip #3 from the Winner of the Advanced Category in the 2013 Scripting Games

In my previous blog article (PowerShell Tip #2), I left off with the subject of inline help and stated there was a better way. I’m fast-forwarding through lots of concepts and jumping right into “Advanced Functions and Scripts” with this tip because they are where you’ll find the answer to a “better way” to add inline help.

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

PowerShell Tip #2 from the Winner of the Advanced Category in the 2013 Scripting Games

Tip #2 - Comment (Document) your code!

This is another one of those tips that probably isn't very popular, but regardless of how good you are at writing PowerShell scripts and functions, they're useless if no one else can figure out how to use them. You might be thinking that you're the only one who uses the PowerShell code that you write, but I'm sure that you like to go on vacation just like the rest of us and none of us are going to live forever.

In my tip #1 blog you learned that you need to "Read the Help!". This tip builds on the first one because it allows others to "Read the Help!" for the PowerShell code that you write.

The type of help that you want to provide for your PowerShell functions and scripts is "Comment Based Help". Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

PowerShell Tip #1 from the Winner of the Advanced Category in the 2013 Scripting Games

In case you haven't heard, the 2014 Winter Scripting Games are just now getting started. Regardless of your skill level with PowerShell, it couldn't be a better time to participate since this is the first time in the history of the scripting games that you'll be able to work as part of a team and receive proactive feedback (before your code is judged) from a team of expert coaches who use PowerShell in the real world on a daily basis. Ultimately, the scripting games make learning PowerShell more interesting and challenging while giving you the opportunity to network with other enthusiasts in the industry.

Now it's time to talk about a PowerShell tip that I wanted to share.

Tip #1 - Read the Help!

While this may not be the most popular tip, believe it or not, it's one of the most important and it's something that's so simple it's often times overlooked. In my opinion, you'll never truly be effective with PowerShell and be able to figure things out for yourself until you learn to read the help.

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

Introducing the Coaches of the 2014 Winter Scripting Games

A few weeks ago, just before the announcement to start recruiting your team for the 2014 Winter Scripting Games, I was contacted by Don Jones and Richard Siddaway about an opportunity to become the Head Coach for the Winter Scripting Games. I was honored to have been contacted and I'm a firm believer of taking advantage of opportunities when they emerge, especially when they're PowerShell related, so I graciously accepted.

One of my first responsibilities was to recruit a small team of coaches. I immediately went to work before potential coaches committed themselves to participating on teams. We had a huge number of people in the PowerShell community who had volunteered to be a coach and while we would have liked to have selected everyone who volunteered, we only had a specific number of positions to fill. Without further ado, here is the list of the coaches for the 2014 Winter Scripting Games:

Name Twitter
Boe Prox @proxb
Carlo Mancini @sysadm2010
Claus Nielsen @claustn
Emin Atac @p0w3rsh3ll
Jan Egil Ring @JanEgilRing
Jeff Wouters @JeffWouters
Jonathan Medd @jonathanmedd
Lido Paglia @nicemarmot
Matt Hitchcock @hitchysg
Rob Campbell @mjolinor
Rohn Edwards @magicrohn
Sahal Omer @GetExchange
Steve Murawski @StevenMurawski

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

People Who are Blogging About the 2013 Scripting Games

I'm sure that most people can easily find any of the blogs of the official judges from the 2013 Scripting Games. I recommend reading those blogs whether you're competing in the scripting games or not since there's a wealth of great information contained in them. The best place to find those blogs if you don't know already is the Judges Notes section under the Scripting Games area on PowerShell.org so there's no reason to duplicate them here.

There are also a number of people who are competing in the Scripting Games that are writing blog articles of their own blog sites. A couple of the ones that I'm aware of are listed below and while they're my competition in the advanced class and have links promoting their Scripting Games entries in their blogs (I do the same thing),  I don't mind promoting their blog articles because there's some great information to be found in them. I'm actually glad they provided links to their entries because both of these guys are excellent PowerShell scripters and you could learn a lot from viewing their Scripting Games entries. Ultimately the scripting games is all about the community learning more about using PowerShell best practices in a friendly competition that's just for fun. Click here to be redirected to the original post of this article on the author's blog site where you can read the remainder of the article.

µ

Skip to toolbar