
For those of you who know me professionally, know that I am a huge advocate for using Windows PowerShell. Many technologies come and go, and when I first got the chance to play with the PowerShell v1.0 beta in 2005 I was hooked. Almost five years later, I strongly feel that it is one of those technologies where my initial impression was right – that it would be around for the long haul. Microsoft started developing PowerShell in 2003 (and I am sure in concept even before that). PowerShell v1.0 was released in 2006, and PowerShell v2.0 was released in 2009. This technology has certainly matured, and in my opinion, every professional who works with the Windows platform (regardless of their role) should know how to use it. SharePoint 2010 utilized PowerShell v2.0, and in fact it is a pre-requisite for installing SharePoint 2010.
From a basic theory perspective, PowerShell is an interactive command-line and task-based scripting technology. Everyone who has used other scripting languages/technologies loathe parsing text for output or to put returned data to use in another script. This is not the case in PowerShell. Through CMDLETs, you deal directly with .NET objects. You can think of a CMDLET as a task orientated tool that performs a specific task. CMDLETS can be joined together in what’s called a pipeline to perform more complex operations.
In SharePoint 2007, one could utilize PowerShell by calling STSADM commands or by importing the SharePoint .NET namespaces and write SharePoint object model code. A developer could also write and compile their own CMDLETs with the SharePoint object model for use within PowerShell. These approaches while very useful, had drawbacks. An admin could say “I’m just going to stick with STSADM and I’m not a developer so the object model is out of the question”. A developer could say “I have Visual Studio and I am comfortable with that”. Well the story changes in SharePoint 2010. Microsoft has published in total well over 600 CMDLETs for SharePoint Server 2010 and it effectively replaces STSADM which had just over 180 commands for MOSS. In SharePoint 2010, PowerShell is the primary scripting/command line tool for administering SharePoint. You’ll have more control than ever in effectively and efficiently administering your SharePoint 2010 environment.
If you are experienced with PowerShell, please feel free to scroll down to the bottom of the article for the PowerShell examples
‘The book’ and online resources to learn about PowerShell
This post is not intended to teach the Basics of PowerShell, rather to introduce its usage for administering SharePoint 2010. With that said, I’ll offer some starting points for those who have not used PowerShell:
Loading your PowerShell environment – You have options
Which PowerShell ’shell’ environment you use is up to you. Out-of-the-box, here are your choices:
Add-PSSnapin Microsoft.SharePoint.PowerShell
You can confirm that the PSSnapin loaded by executing the following command. Note this outputs a listing of only the PSSnapin names using a pipe to Format-Table (or ft for short) and selecting the Name property. This will in fact show you all of the PSSnapins loaded in your shell:
Get-PSSnapin | ft Name
Using your PowerShell profile to automatically load Microsoft.SharePoint.PowerShell in Windows PowerShell and the Windows PowerShell ISV
If you choose to use the Windows PowerShell or Windows PowerShell ISV for working with SharePoint, I’ll admit that it would be slightly annoying to have to manually load the Microsoft.SharePoint.PowerShell PSSnapin every time you want to use PowerShell. To solve this, you can use your PowerShell profile. Briefly, your PowerShell profile is a PowerShell script that loads every time you load the environment and it’s where you can place commands that you want to execute as your shell is loaded. For more info on your PowerShell Profile, see TechNet article about_profiles (which I would recommend that you read in its entirety).
For the purposes of this article, I’ll show you how to identify if you have a ‘Current User, Current Host’ profile.
To identify if you have a ‘Current User, Current Host’ profile within Windows PowerShell and the Windows PowerShell ISV, execute the following (note, returns True or False)
test-path $profile
If this returns false, you can automatically create a profile for yourself by executing the following. Note that this will not overwrite a profile if it exists.
if (!(test-path $profile))
{new-item -type file -path $profile -force}
Now that you have a profile, you can insert the Add-PSSnapin command above. To do this, open your profile from PowerShell:
notepad $profile
Simply copy and paste the Add-PSSnapin command as listed above, save then close the file. Close then re-open PowerShell. You’ll now have the Microsoft.SharePoint.PowerShell PSSnapin loaded every time you open PowerShell.
Additional must know items about your profile:
- Windows PowerShell and Windows PowerShell ISV have different ‘Current User’ Current Host profiles. So if you use both, you’ll want to keep that in mind.
- The SharePoint 2010 Management Shell also has profile options, but uses a different profile. By default, it uses the ‘All Users, Current Host’ profile.
- Since your profile is a PowerShell script, you’ll need to ensure that scripts are allowed to run on your computer. There are different Execution Policy settings for running scripts within PowerShell. By default, the Execution Policy is ‘Restricted’ which prevents all script files from executing. You’ll need to change this to another value. I suggest that you read the TechNet article about_Execution_Policies. On my development machine, I use ‘RemoteSigned’ however I recommend that you investigate the various settings and use the one that fits for your own security requirements. For production environments, you’ll want to consider using a more secure Execution Policy.
Getting started with PowerShell Examples – Discovering what you can do
The first question I asked was ‘What SharePoint related CMDLETs are installed out-of-the-box, and where do they live on my system?”.
Discover what SharePoint related CMDLets are installed in your environment – shows a long table based listing):
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell
That is great, but I want to see more detail than that about each command. Pipe to Format-List (fl for short) – this will show more properties of each command, again this will show an even longer listing:
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell | fl
Well can I see all of the properties for each command? Sure thing…
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell | fl -property *
How many SharePoint CMDLETs are there on my system?
(Get-Command -PSSnapin Microsoft.SharePoint.PowerShell).count
Where do they live on my system? Well they are all a part of a SharePoint related .dll that is in your GAC (Global Assembly Cache). To prove it, execute the following to get all of the unique assemblies that are associated with the Microsoft.SharePoint PSSnapin:
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell | select DLL -unique
One thing that I found interesting on the file system is the contents of the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL” folder. This is a new folder within SharePoint 2010 (i.e. CONFIG\POWERSHELL didn’t exist with SharePoint 2007) and contains all of the SharePoint PowerShell registration and type configuration files. Take a look!
So how can I see all of the commands that contain SPWEB in the noun of the command?
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell -noun "SPWEB*"
I want that SPWEB CMDLET list to be sorted alphabetically by command name! No problem…:
Get-Command -PSSnapin Microsoft.SharePoint.PowerShell -noun "SPWEB*" | Sort verb
How do I know what a specific command does? Let’s look at the SPWeb CMDLET. Use Get-Help:
Get-Help Get_SPWeb
How about an example of getting an SPWeb. This isn’t entierly useful all by itself but…
Get-SPWeb "http://yoursharepointsite"
To see all of the members of the SPWeb. The Get-Member (gm for short) CMDLET will show you this information:
Get-SPWeb http://yoursharepointsite | gm
To see all of the properties associated with a specific SPWeb. Inspect the object with this command:
Get-SPWeb "http://yoursharepointsite" | fl -property *
Here is an example of updating the SPWeb Title:
$myweb = Get-SPWeb "http://yoursharepointsite" $myweb.Title = "My New Site Title" $myweb.Update()
I think this is enough to get you started.
Cheers,
c.
[...]The information mentioned in the article are some of the best available [...]……
[...]below you’ll find the link to some sites that we think you should visit[...]……
Websites we think you should visit…
[...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]……
Awesome website…
[...]the time to read or visit the content or sites we have linked to below the[...]……
Great website…
[...]we like to honor many other internet sites on the web, even if they aren’t linked to us, by linking to them. Under are some webpages worth checking out[...]……
[...]Sites of interest we have a link to[...]……
[...]usually posts some very interesting stuff like this. If you’re new to this site[...]……
Online Article……
[...]The information mentioned in the article are some of the best available [...]……
Found=> likes your page…
[...] Occasionally each of us choose blogs that people read. Let uѕ discuss the modern sites that anу оf uѕ choose [...]…
Informative and precise…
Its hard to find informative and accurate information but here I noted…
will smith net worth 2009…
[...]to Lennox right after Lennox’s authorized crew lodged points of law with the Northern Eire courts stating [...]…
Websites you should visit…
[...]below you’ll find the link to some sites that we think you should visit[...]……
Recommeneded websites…
[...]Here are some of the sites we recommend for our visitors[...]……
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
greenpeace mexico bomba…
[...]unlikely there will be any news from the courts regarding an charm decision[...]…
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
Websites worth visiting…
[...]here are some links to sites that we link to because we think they are worth visiting[...]……
Great website…
[...]we like to honor many other internet sites on the web, even if they aren’t linked to us, by linking to them. Under are some webpages worth checking out[...]……
Sources…
[...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]……
Sites we Like……
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]……
Lakás zöldkártya…
[...]below you’ll find the link to some sites that we think you should visit[...]…
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
Read was interesting, stay in touch……
[...]please visit the sites we follow, including this one, as it represents our picks from the web[...]……
Check this out…
[...] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[...]……
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
Sites we Like……
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]……
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
You should check this out…
[...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]……
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
Links…
[...]Sites of interest we have a link to[...]……
Links…
[...]Sites of interest we have a link to[...]……
Awesome website…
[...]the time to read or visit the content or sites we have linked to below the[...]……
Cheap Yankee Candles…
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
Read was interesting, stay in touch……
[...]please visit the sites we follow, including this one, as it represents our picks from the web[...]……
abbotcy…
uggs boots saleYour whole entire body will stay cozy and there can be no odds of getting a chilly at all…
You should check this out…
[...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]……
You should check this out…
[...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]……
Websites you should visit…
[...]below you’ll find the link to some sites that we think you should visit[...]……
Great website…
[...]we like to honor many other internet sites on the web, even if they aren’t linked to us, by linking to them. Under are some webpages worth checking out[...]……
Sources…
[...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]……
Wholesale Yankee Candles…
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]…
soap news…
[...]ready short even though ago, “Mom athlonsports are exceeded shin as well as knee players, I [...]…
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
Websites you should visit…
[...]below you’ll find the link to some sites that we think you should visit[...]……
Superb website…
[...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]……
will smith quotes treadmill…
[...]I wouldn’t be ready to pursue all of these distinct objectives whilst simultaneously dedicating the electricity [...]…
Windows 8…
[...]we like to honor other sites on the web, even if they aren’t related to us, by linking to them. Below are some sites worth checking out[...]…
weight loss…
awesome info very apreciate…
truyen ma, nghe doc truyen ma kinh di…
I must thanks over here best blog. truyen ma kinh di…
Tumblr…
Tumblr linked to this site…