* Free Webinar *
Build SharePoint 2013 Application Solutions - All You Need is a Browser!
Thursday 25 April at 11am PDT. Register now! Space is limited.

* Free Whitepapers *



* Free Trials *





* Get a Free SharePoint Art of the Possible Presentation for your Business *
Contact Joel Oleson
I'm now consulting with Salient 6
Friendly Sponsored Ads

BlueStripe
Metalogix
SharePoint Joel's SharePoint Land > Posts > Commandlets are an Admins Best Friend: Powershell 101 (2 of 3)
Commandlets are an Admins Best Friend: Powershell 101 (2 of 3)


Guest blog post from my operations friend Josh Boyles (I'll have to remind him to get a twitter account so you can let him know what you think of his post… especially since I know the comments on my blog at this moment are painful.)

Last time we gave a little bit of an introduction. Today we're getting right down to it. Time to get our hands dirty with a little powershell. And when I say get our hands dirty I mean we're going to be typing on keyboards, and those are disgusting.

    I'm going to assume you're at least a little familiar with PowerShell. If not, go read the last post. In PowerShell you use what are called "commandlets." And what are those?

 

Commandlets are an Admins Best Friend

 

In this metaphor Marilyn Monroe is a SharePoint admin. Which is probably what she would've done if she hadn't made it big in the pictures.

 

    Commandlets are the easiest way to get things done with PowerShell. Sure, you can program commands yourself and do everything the hard way, but commandlets are little programs that already do the things you most likely want to do. Think of it like the difference between assembly code and python. Sure, you could write how to add two numbers in assembly, but it would take way too much work and end up pretty ugly. With python, you just write 1 + 1 and hit enter.

    There are over 100 Commandlets (or is it CommandLets? Microsoft has some weird obsession with capital middle letters) built into PowerShell itself, but the real power comes from the fact that most major Microsoft products have snapins or modules built by the product team. A snapin is a collection of commandlets specific to a certain product. A module is a little bit more than a snapin, but we won't get into that because in SharePoint 2010 snapins are still used.

    So let's use the commandlet to import the snapin as our first example (that's called recursive learning … a method I just made up) -- (wait a second, I just went and looked it up just to be sure and, not only did I not invent it, recursive learning isn't even close to what I didn't invent). Where were we before all those parentheticals? That's right, importing a snapin using a commandlet. So, we open up PowerShell and, in the command line window that opens, type in:

 

PS C:\>add-pssnapin microsoft.sharepoint.powershell

 

    Tap our shoes together three times, hit enter and … our PSSNAPINS are imported! All commandlets follow the same pattern you see here. The first word is a verb, then a hyphen, then a noun, like so:

 

Add-PSSnapin

 

You start with what is going to happen (in this case, we're ADDING something, so it starts with add) and end with a noun representing what will be acted upon (in this case, it's a pssnapin, or PowerShell SnapIn).

    This format is INCREDIBLY useful when we try to search for commands, but we'll get into that in a second.

    Back to our example, we're adding a pssnapin, and then the next bit is the pssnapin that's getting added here. The section following the command is where you put options, sometimes referred to as switches, arguments, parameters, etc. Depends on which side of the tracks you come from.

Whatever you call them (and we will call them parameters from here on out), in powershell they are indicated by a dash, followed by the name of the parameter, then a space, then any input for that parameter (not all parameters need input). For example, if we wanted to get technical with our add-pssnapin, what we should've written was this:

 

PS C:\>add-pssnapin -name microsoft.sharepoint.powershell

 

    In that case we see that the option is -name and the input is microsoft.sharepoint.powershell. You probably also noticed we left out the -name up above. That's because many commandlets have a default parameter. If there's no parameter specified PowerShell assumes that whatever comes next is the default parameter. This is very useful, but can also be a little dangerous if you're not careful, so when in doubt, just include the parameter.

    One thing to note. If you're not familiar with autocomplete then OH MY GOODNESS YOU ARE MISSING OUT! Seriously, autocomplete is a revelation. My background is in Linux, so when I came to the Microsoft world and found out tab complete worked in PowerShell I was happy as a clam.

    Anyway, as I was saying, in PowerShell you can hit tab if you're halfway through writing something and PowerShell will try to fill in the rest. So if you type "Get-comm" and hit tab it will finish out the "command." Or if you're typing out a super long file name you can get a few letters in and just hit tab and PowerShell will fill in the file name. It's amazing. So if you're not sure what options are available, you can also just put in a dash after a command and start going to town on the command key.

comments powered by Disqus

 20 Recent Posts

Product Analysis: OnePlaceMail 6.4 by ScinapticUse SHIFT+ENTER to open the menu (new window).New
THE Microsoft SharePoint Conference 2014 in Las Vegas March 3-6 #SPC14Use SHIFT+ENTER to open the menu (new window).
Yammer Integration with SharePoint Online begins with a link in Office 365Use SHIFT+ENTER to open the menu (new window).
SPTechcon Boston 2013 – What are you waiting for?Use SHIFT+ENTER to open the menu (new window).
Announcement: 11 Keys to Optimizing SharePoint for Field Personnel and Traveling Executives Use SHIFT+ENTER to open the menu (new window).
Watch TechEd 2013 SharePoint Related Sessions On Demand #MSTechedUse SHIFT+ENTER to open the menu (new window).
Southern California Tour: June 25-27 #SANSPUG San Diego #OCSPUG Orange County #LASPUG Los AngelesUse SHIFT+ENTER to open the menu (new window).
The Quest Has Begun – To See Every Country in the World by Age 50Use SHIFT+ENTER to open the menu (new window).
Announcement: EMC Releases new Documentum Connector for Microsoft SharePointUse SHIFT+ENTER to open the menu (new window).
Seriously Time to Revisit Your Enterprise Browser StandardsUse SHIFT+ENTER to open the menu (new window).
SharePoint Governance Infographic and Strategic PlanningUse SHIFT+ENTER to open the menu (new window).
Still Sad Story: Office 64 & IE 64 with SharePoint 2013Use SHIFT+ENTER to open the menu (new window).
ANNOUNCEMENT: CacheFront Professional Open Beta Sign-Ups Now OpenUse SHIFT+ENTER to open the menu (new window).
SharePoint 2013 Analytics A Big Step BackwardUse SHIFT+ENTER to open the menu (new window).
Product Analysis: Metalogix Replicator for SharePointUse SHIFT+ENTER to open the menu (new window).
ANNOUNCEMENT: CipherPoint Releases Content Scanner and Version 1.9 Transparent Encryption Software, Adds Support for SharePoint 2013, and File ServersUse SHIFT+ENTER to open the menu (new window).
Blog Talk Radio: Collaboration Tech Talk - SharePoint 2013 InsightsUse SHIFT+ENTER to open the menu (new window).
Utah SharePoint Business Value Workshop 2013 and Art of the PossibleUse SHIFT+ENTER to open the menu (new window).
SharePoint 2013 Browser Comparison Report CardUse SHIFT+ENTER to open the menu (new window).
ANNOUNCEMENT: Metalogix Launches Content Matrix Migration Express to Simplify and Speed Up SharePoint Migrations On-Premises or in the CloudUse SHIFT+ENTER to open the menu (new window).