Inconvenient Settings Loss With Dismount-SPContentDatabase
Are you someone that likes to go through your web applications and dismount your databases prior to patching? Or maybe you’re just moving a content database from one web application to another. Or maybe, just maybe, you want to dismount a content database for the fun of it!
Well, if that’s you, you might have noticed (or maybe not), that when the content database is remounted, a few properties get reset to their default values such as MaximumSiteCount and WarningSiteCount (2,000 and 5,000 respectively). This can be pretty inconvenient (to say the least!) if you’ve modified these settings in any way and even more inconvenient if you didn’t document them before running Dismount-SPContentDatabase.
Once again, it’s our friend PowerShell to the rescue. The following functions allow you to dismount all of the content databases in a given web application (Dismount-SPContentDatabases) while retaining the pertinent settings in CSV file. The function helpfully titled Mount-SPContentDatabases will remount the content databases (using Mount-SPContentDatabase) to the supplied web application using the previous settings (including the original DatabaseServer), thus saving you at least 5 minutes to enjoy an additional cup of coffee.
Example Use
Imagine you have a web application with the name ContosoIntranet.
- Dismount-SPContentDatabases http://intranet.contoso.com
- Mount-SPContentDatabases http://intranet.contoso.com (Join-Path $pwd “ContosoIntranet_ContentDB.csv”)
SharePoint 2010: Setting The UIVersion with PowerShell for a Content Database
A recent client engagement had me flipping back and forth between the v3 and v4 UI (Visual Upgrade) for a number of site collections in a given content database.
The PowerShell function outlined below allows for setting the UIVersion on all of the site collections and sites in a given content database in one shot.
Retrieving SharePoint 2010 Farm Solutions with PowerShell
The following PowerShell script allows for saving all of the farm level solutions in a SharePoint farm.
The Script
or the one liner:
(Get-SPFarm).Solutions | ForEach-Object{$var = (Get-Location).Path + "\" + $_.Name; $_.SolutionFile.SaveAs($var)}
SharePoint 2010: Creating a Folder Hierarchy Based on a Term Set with PowerShell
Long winded title, but it says it all. I recently had a need to create a nested folder hierarchy in a document library based on a managed metadata term set with almost 1,000 terms. The following PowerShell script will create a nested folder structure within a target document library based on the supplied term set.
The Script
Importing Terms from CSV in PowerShell
As the Term Store Management Tool in SharePoint 2010 does not allow for delta imports, the following PowerShell script will consume a .csv file and import the terms into the term store for the supplied term set if they do not yet exist.
File Format
| Term |
| Sample Term 1 |
| Sample Term 2 |
| Sample Term 3 |
The Script
Export a Term Set to CSV with Identifiers in PowerShell
I recently had a need to export all of the terms from a given term set in a SharePoint 2010 Managed Metadata Service application to CSV for consumption in another process. The following PowerShell script will create a .csv file with all of the term names and identifiers for the supplied Term Store/Term Store Group/Term Set.
Updated: There was an error in the previous version of this script. It did not account for the fact that the ampersand character (“&”) is stored as a fullwidth ampersand (“\uFF06”) when a term is created. The script has been adjusted to replace any fullwidth ampersands with a basic Latin ampersand in the output.
The Script
SharePoint 2007 PowerShell Profile
The following is the Powershell profile that I have been using on the SharePoint 2007 farms I administer.
Reference
SharePoint 2010 Products scripted deployment
It seems I missed it when Microsoft published the SPModule PowerShell module to aid in a scripted installation of a SharePoint 2010 farm.
If anything, it can serve as a handy guide for how to script out individual actions pertaining to installation and farm maintenance.
Reference
SharePoint 2010: Provisioning a new Farm with Powershell
SharePoint 2007 always required some level of scripting in it’s installation to allow for greater control of the installation process (i.e. creating database names without GUIDs). SharePoint 2010 is not any different in that scripting is still required to gain the finer control over installation. What has changed is that now PowerShell can be used in place of psconfig/stsadm. With that in mind, let’s begin.
- Install the SharePoint binaries on each server in your farm. Select “Complete” as the installation type. This will allow you to create a farm as opposed to a single server installation.After the install has completed, you will asked if you would like to complete the “SharePoint Products Configuration Wizard”. Do not run the wizard at this time.
- On the server which you wish to provision Central Administration:
- Open the ”SharePoint 2010 Management Shell” (right-click and select “Run as administrator”). The shell will load with a message that the local farm is not accessible. This is expected as we have only installed the binaries.
- Run the following command to create the initial configuration/content database for the farm.
New-SPConfigurationDatabase –DatabaseName “SharePoint2010_Config” –DatabaseServer “SharePoint2010SQL” –AdministrationContentDatabaseName “SharePoint2010_Content_Admin” –Passphrase (ConvertTo-SecureString “Pass@word1” –AsPlaintext –Force) –FarmCredentials (Get-Credential) - After the initial creation of the farm, close and reload the “SharePoint 2010 Management Shell”. You should no longer receive any error messages.
- Install the help files.
Install-SPHelpCollection -All - Secure the resources used by the server (files and registry).
Initialize-SPResourceSecurity - Install and provision the farm services.
Install-SPService - Install the features on the server.
Install-SPFeature –AllExistingFeatures - Provision Central Administration.
New-SPCentralAdministration -Port 1234 -WindowsAuthProvider "NTLM" - Install the application content.
Install-SPApplicationContent - Optional: Disable the loopback check. If this is a development install, outright disabling the check should be fine. For production environments, the loopback check should be left in place and BackConnectionHostNames should be used in its place. See KB 896861.
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword
- On each additional server that you wish to converge in the farm:
- Open the ”SharePoint 2010 Management Shell” (right-click and select “Run as administrator”). The shell will load with a message that the local farm is not accessible. This is expected as we have only installed the binaries.
- Connect the server to the farm with the following command:
Connect-SPConfigurationDatabase -DatabaseName "SharePoint2010_Config" -DatabaseServer "SharePoint2010SQL" -Passphrase (ConvertTo-SecureString "Pass@word1" -AsPlaintext -Force) - Install the help files.
Install-SPHelpCollection -All - Secure the resources used by the server (files and registry).
Initialize-SPResourceSecurity - Install and provision the farm services.
Install-SPService - Install the features on the server.
Install-SPFeature –AllExistingFeatures - Install the application content.
Install-SPApplicationContent - Optional: Disable the loopback check. If this is a development install, outright disabling the check should be fine. For production environments, the loopback check should be left in place and BackConnectionHostNames should be used in its place. See KB 896861.
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword
Reference
Getting Started With Windows PowerShell and SharePoint
Today was my first experience with PowerShell, and I have to say I’m impressed. PowerShell truly does appear to be a command prompt for the .NET generation. While it can be agravating at times, I can see PowerShell quickly becoming a “can’t do without” tool in my arsenal.
Resources: