Patience…

August 21, 2009 2 comments

Over the next week I am going to model and remodel this blog until i get it laid out in a way that is both functional and aesthetically pleasing to me. Hopefully, I will come across someone else’s words of wisdom. yay to learning yet another interface.

Categories: Odds & Ends

My First PowerShell… Select a specific web application

August 20, 2009 2 comments

Lately, I have been spending some time on migrating a client’s SharePoint collaboration sites from http to SSL. Thanks to the clients farm configuration, the migration is fairly straight-forward though tedious, so I decided to make this my opportunity to start getting familiar with PowerShell. Two quick points on PowerShell:

1. It’s as awesome as everyone says it is, really. PowerShell is without a doubt one of the most entertaining tools in the MSFT bag these days. Once you start toying around with PowerShell, it’s like walking into the tootsie roll commercial. Everything you think you see becomes a PowerShell script to me.

2.  It is easier than it looks at a glance. I am not a developer, nor would I say that i am even a scripter. PowerShell is my first time doing more than using someone else’s vbscript or modifying ini/cfg/ xml. I have been able to get up to speed fairly quickly using the wealth of resources available on the web and through friends.

As a precursor, I will do my best to keep from rehashing content you can find somewhere else, so if you need an intro to PowerShell, then google “SharePoint PowerShell” on Bing.com and go to town. I also recommend PowerShell.com as a great resource; where there is even a pdf ebook which was written by the PowerShell MVP who maintains the site that is available there as a free download.

The task I wanted to automate was the updating of the portal site connection links between parent and child site collections in the client’s collaboration area, but this should only serve to illustrate the underlying functionality. All of the sites exist within a single web application where there is a single parent site collection with all other site collections logically beneath it. The limiting factor is that there are a number of web applications which are hosting SharePoint sites that will not be immediately transitioned to SSL.

The steps, as I originally planned them:

1. Initialize the farm

2. Initialize/identify the web application

3. Return the list of site collections in the web application

4. Iterate through the list, updating the portal site connection path

Some quick help for deciphering the following script…

To interact with the SharePoint from PowerShell, at the console enter:

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

Some definitions:

Terms / Symbols Definition
$<text> A variable which defaults to an array when there is more than one variable
$_ The current item in the array
% Foreach
| Pipelines the output from the preceding statement into another cmdlet

$<someObject> | get-member is an easy way to see all of the available methods and properties for the object:

1. Initialize the farm

Initializing the farm was pretty easy, all I had to do was enter a line easily found on any SharePoint + Powershell site,

$spfarm = [Microsoft.SharePoint.Administration.SPFarm]::Local

This gave me an object which I could use to identify the web applications in the farm. Progress!

2. Initialize/Identify the web application

This is where it all of a sudden became tricky for me. There are a number of posts about returning all of the sites in the farm or working with a site based on url, but there did not seem to be anything which mapped to what i was trying to do (at least, of course,  until after i had already done this). A friend pointed me at “$wa = $spfarm.getobject($guid)” which is a method which will return any object in the farm based on the GUID specified in the variable $guid. And actually, that isn’t so bad over-all, especially since it is short and sweet, but I don’t like GUID’s very much. I prefer to cut and paste where possible to avoid typos, and GUID’s are not exposed through the UI very well. Fun Tip: right-click is paste in PowerShell.

End result being,

$waName = “SharePoint – 80”

$wa = $spfarm | %{$_.Services} | where-object {‘$_.TYPEName -eq “Windows SharePoint Services Web Application”‘} | %{$_.WebApplications} | %{Write-Output $_} | where-object {$_.Name -eq $waName}

3. Return the list of site collections & 4. Iterate through the list, updating the portal site connection path

The truth is that this part was so easy it does not make any sense to talk about them separately. I needed 4 steps to organize my thoughts on how this was going to behave but PowerShell does not. In both instances there is an existing method which served my purposes. I’ll show then tell:

$newPortalURL = “https://something.sample.local&#8221;

$wa.Sites | %{$_.set_portalURL($newPortalURL)

$wa.Sites returns the list of site collections in the web application, and the method it feeds sets the URL in the portal site connection equal to the value of $newPortalURL.

So now that I have all of my steps mapped out, it was time to make something more portable out of it, and no, I’m not going to put in error handling at this time.

UpdatePortalURL.ps1 File Contents

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

$waName = $args[0]

$newPortalURL = $args[1]

$spfarm = [Microsoft.SharePoint.Administration.SPFarm]::Local

$wa = $spfarm | %{$_.Services} | where-object {‘$_.TYPEName -eq “Windows SharePoint Services Web Application”‘} | %{$_.WebApplications} | %{Write-Output $_} | where-object {$_.Name -eq $waName}

$wa.Sites | %{$_.set_portalURL($newPortalURL)}

Usage: UpdatePortalURL.ps1 “SharePoint – 80” “http://something.sample.local&#8221;

On a final note, was this difficult? Definitely not, the important part was getting familiar with PowerShell, realizing that there are a whole slew of methods available at the web application and site collection level. Not difficult does not mean trivial, and probably the most important thing I have done so far is to spend some time in PowerShell every day. The main point of the sample script in this post was to give myself a baseline for the creation of even better PowerShell scripts and functions down the road. Keep an eye out for the next task, loading up a few thousand files from a file share into library.

When Your SharePoint Server Cannot Access the Internet

August 20, 2009 Comments off

In consulting and in Federal Agencies, it is very common to find oneself without access to the internet from the servers that are running SharePoint. In this scenario, SharePoint Central Administration and SharePoint sites in general load noticeably slower than when the internet is available. One of the handy tricks that I have managed to pass on to many of my colleagues and customers is how to speed up SharePoint page load times in this specific situation. This fix is not my own and full credit goes to the blogger who originally posted and a friend for finding the post in the first place, but I get asked about it so frequently that I wanted to have an easy to reference location for providing the information. Simply put, the signed .NET controls in SharePoint are trying to phone home to verify their signatures. When the internet is not available this can impose from 30 seconds to 2 minutes worth of waiting for a given page to load. Running the following vb script on each of the SharePoint servers that serve up pages will completely remedy the situation. Simply copy and paste the following text into a file, save it as .vbs, and run it on your servers.

Contents of spinup.vbs

const HKEY_USERS = &H80000003

strComputer = “.”

Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” _

& strComputer & “\root\default:StdRegProv”)

strKeyPath = “”

objReg.EnumKey HKEY_USERS, strKeyPath, arrSubKeys

strKeyPath = “\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing”

For Each subkey In arrSubKeys

objReg.SetDWORDValue HKEY_USERS, subkey & strKeyPath, “State”, 146944

Next

msgbox “Done!”

If anyone knows the blog post I am talking about, please let me know so I can link back to it.

Categories: SharePoint 2007

In case you’re curious

August 19, 2009 1 comment

My name is Ben Peters and I am a SharePoint Architect for Planet Technologies (read msft gold partner) in the DC Metro area. I work primarily in the federal space and I am all about SharePoint. I am starting this blog as much for my own peace of mind as anything else (ok Clay pretty much guilted me into it), but honestly i am plain tired of forgetting how i did this, that, or the other thing(where are you custom tree navigation w/ css, auto expand/collapse, and location awareness!). If someone finds these tid-bits useful, all the better.

Categories: Odds & Ends