Archive for the Category SMS Scripting


Got PowerShell Figured Out Yet?

Here’s the answer from our new best friend Gary.

His post covers:

  • -loops
  • -variables
  • -arrays
  • -math
  • -string concatenation
  • -output

In this post, he shows us how adding:

> .\filename.txt

to a command writes the output to a file in the current directory and also how adding:

 | format-list 

to a command converts our output from a nice table with headers and everything to a list with space to be more verbose. For example, try these two:

get-process winlogon

and this:

get-process winlogon | format-list

This is the most I’ve learned in the shortest amount of time in a long time. Especially if you count the fact that I now know there’s only four perfect numbers less than 200,000.


Continuing with SharePoint Management Shell

First of all, to echo a point we made a few days ago, our new best friends at Acme Solutions talk about SMS here. They agree that it will be the tool of choice for the SharePoint 2010 administrator.

Then, since we’re still trying to get our feet under us in this environment, we found this from our new best friend, Gary. He confirms we we had said earlier that SMS is just MS PowerShell with SharePoint 2010 library added in and he proves it by looking at the shortcut properties when you right click on Start | Programs |SharePoint 2010 | SharePoint Management Shell.

Here we see the target is just:

-NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\
Web Server Extensions\14\CONFIG\POWERSHELL\Registration\
\sharepoint.ps1 ' "

Here we see that the shortcut is just a PowerShell Script of it’s own:

$ver = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home

We looked at the Add-PSSnapIn command previously and turns our PowerShell environment into a SharePoint Management Shell environment by adding the microsoft.sharepoint.powershell library. But this also shows us that we can set variables using the $VariableName = Value format.

Prove that to yourself by opening PowerShell and enter:

$robot = "I Love Robots"

and then do:


So we’re checked out on setting PowerShell variables.

Finally, the SharePoint.ps1 script includes a largish #sig block of apparently random characters. I presume this has something to do with signing scripts. Recall in our create and delete script that we did last week, we included a   line that said:

Set-ExecutionPolicy RemoteSigned

Now, obviously, I plagerized this from somewhere becasue you all know as much about this or more than I do. And I apologize to my source, whoever you are, because I also try to credit you guys when we benefit from your genius. But, since it’s escaped me, I can only say that I recall reading that this command will allow local scripts to run unsigned but still require remote scripts to have a signature. I’m guessing this big block of characters has something to do with that kind of signature.



Windows PowerShell 2.0

So, we’re looking at this SharePoint Management Shell and learning a bit about it. One thing for sure, if you’re a SharePoint admin you’re going to want to run Windows PowerShell locally.

Here’s the download page from TechNet

This is what Microsoft calls its “Core Management Framework” which includes the Remote Manager and the Background Intelligent Transfer Service (BITS.) The download I chose for my XP laptop did not include the BITS component. When it’s installed, you get the command line interface and the “Integrated Scripting Environment.” They appear under Start | Programs | Accessories | Windows PowerShell.  

Also, there’s a decent intro to PowerShell scripting from our new best friend Todd on TechNet here.


Windows PowerShell and the SharePoint Management Shell

If you’re an expert at this then you’re ahead of me here. My new install of Server 2008 R2 includes a Windows PowerShell (WPS) and my SharePoint install includes a SharePoint Management Shell (SMS).

I found this on MSDN where they explain that SMS is just WPS with the SharePoint PowerShell snap-in added. Also, this is part of the move away from the Shared Service Provider to a more generic Service Application Framework that will support all of Office 14. Here, we can see that Microsoft claims this approach will improve development, integration, load balancing, authentication and back-up\restore.

There’s also a discussion of the PowerShell and SharePoint Foundation here where you’ll find links to the beginner guides for WPS.

I also found the help file for the SMS Cmdlets here. This page is labeled for the Search Server 2010 Express but the SharePoint 2010 Beta commands are included in the third of the three help files listed.

Finally, our new best friend David explains here that cmdlets can be written into a .psl file and run from the PS> prompt as well as where to find your $profile so you can add the SharePoint cmdlets into your generic PowerShell environment.