* 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

SharePoint 2013 Analytics A Big Step BackwardUse SHIFT+ENTER to open the menu (new window).New
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).
Product Analysis: The Next Generation harmon.ie 4.0 Enables True SharePoint Mobile EnterpriseUse SHIFT+ENTER to open the menu (new window).
Announcement: FREE LIVE Web Seminar—SharePoint2013: Key Strategies to Effectively Govern and Secure Sensitive DataUse SHIFT+ENTER to open the menu (new window).
Going on Tour… Southern California SharePoint User Group TourUse SHIFT+ENTER to open the menu (new window).
The HOT debate #SPJam… the Future of Social Enterprise at Microsoft with Yammer and SharePointUse SHIFT+ENTER to open the menu (new window).
Free Webcast: What you should do before, during and after migration to SharePoint 2013 or Office 365Use SHIFT+ENTER to open the menu (new window).
Free Webinar: Improving the SharePoint Experience with Insights from Web AnalyticsUse SHIFT+ENTER to open the menu (new window).
Advertisement: Managing SharePoint TrafficUse SHIFT+ENTER to open the menu (new window).
Must Read Articles to Understand PC DeclineUse SHIFT+ENTER to open the menu (new window).
Announcement: FREE CloudShare HANDS-ON Webinar: Build SharePoint 2013 Application Solutions - All You Need is a Browser!Use SHIFT+ENTER to open the menu (new window).
FREE Webinar: How to Protect Your Sensitive DataUse SHIFT+ENTER to open the menu (new window).
It’s Official. I’m working for Salient6Use SHIFT+ENTER to open the menu (new window).
SPChitChat – Nestivity Community Experiment for the SharePoint CommunityUse SHIFT+ENTER to open the menu (new window).
Announcement—FREE White Paper: Bridging the Gap—Replacing Lost Offline Capabilities When Migrating From Notes to SharePointUse SHIFT+ENTER to open the menu (new window).