One example of how PowerShell can help you in your SharePoint migration and upgrade tasks is directory comparison. I’ve used many tools for directory comparison before, but this is hands down the easiest when PowerShell is already installed. In three lines, you have a list of Features installed on one web front end but not the other.
The solution is based on two out of the box PowerShell commands and one PowerShell principle.
- Dir command – lists the files and folders in a directory
- Compare-Object command – given two lists, display the differences
- $variables assignment – assign the directory listing to a variable for use later
Starting a new project, I was faced with the challenge of reproducing some of an existing farm on my development machine. I was given installation instructions and a copy of the 12 hive. After following the instructions, the customizations were failing on a missing feature. Using the powershell script above to compare my new SharePoint Root TemplateFeatures directory to the copy from production, I was able to identify the missing features and subsequently locate the Solution Package that hadn’t been included in the installation instructions.
Applications for Upgrade and Migration
Besides development, SharePoint upgrades and migrations are both common scenarios when directory comparison is important. Through some trial and error, you may be able to determine SharePoint Root Directory modifications that were made manually versus those deployed through SharePoint Solution Packages. Install a package, compare to the root you are trying to reproduce and repeat, until you’ve added all of the solution packages you have available. The Features that still show are the ones deployed manually or by packages you don’t have. Create a package for the new features and you will be ahead of the game next time you need to add a Web Server to your Farm or upgrade to SharePoint 2010.