Logo
programming4us
programming4us
programming4us
programming4us
Windows XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
 
Windows Server

Managing SharePoint 2010 with Windows PowerShell : Managing Permissions in SharePoint 2010, Managing Content Databases in SharePoint 2010

12/4/2012 6:21:06 PM

1. Managing Permissions in SharePoint 2010

Running the SharePoint 2010 cmdlets in Windows PowerShell requires the user to be a member of the SharePoint Shell Access role in the configuration database, and the WSS_ADMIN_WPG local security group on the SharePoint 2010 server.

The Add-SPShellAdmin cmdlet is used to add users to the SharePoint Shell Access role and to the WSS_ADMIN_WPG local security group on all servers that have the SharePoint Foundation 2010 Web Application role. To add a user to the SharePoint Shell Access role for a specific database, you can type:

PS > Add-SPShellAdmin -UserName powershell\nigo '
>> -database (Get-SPContentDatabase -Identity WSS_Content)
PS > Get-SPShellAdmin
UserName
--------
POWERSHELL\nigo

In this example, we use the Add-SPShellAdmin cmdlet to add the user “powershell\nigo” to the SharePoint Shell Access role in the WSS_Content database and the farm configuration database. Notice how we also use the Get-SPContentDatabase cmdlet to retrieve a specific content database. If you do not specify a database, the user will be added only to the SharePoint Shell Access role in the farm configuration database.

The Get-SPShellAdmin cmdlet returns the login names of users who have the SharePoint Shell Access role in a specific database. You can use the cmdlet by typing:

PS > Get-SPShellAdmin (Get-SPContentDatabase -Identity WSS_Content)

UserName
--------
POWERSHELL\nigo

It is also possible to remove users from the SharePoint Shell Access role using the Remove-SPShellAdmin cmdlet as demonstrated in the example below.

PS > Remove-SPShellAdmin -UserName powershell\nigo '
>> -database (Get-SPContentDatabase -Identity WSS_Content)

2. Managing Content Databases in SharePoint 2010

Windows PowerShell includes eight cmdlets that you can use when working with the SharePoint 2010 content database. To retrieve a list of all content database cmdlets available, use Get-Command with the Noun parameter to list all cmdlets where the noun is SPContentDatabase:

PS > Get-Command -Noun SPContentDatabase

CommandType   Name                         Definition
-----------   ----                         ----------
Cmdlet        Dismount-SPContentDatabase   Dismount-SPContentDatabase
Cmdlet        Get-SPContentDatabase        Get-SPContentDatabase [[-Id
Cmdlet        Mount-SPContentDatabase      Mount-SPContentDatabase [-N
Cmdlet        New-SPContentDatabase        New-SPContentDatabase [-Nam
Cmdlet        Remove-SPContentDatabase     Remove-SPContentDatabase [-
Cmdlet        Set-SPContentDatabase        Set-SPContentDatabase [-Ide
Cmdlet        Test-SPContentDatabase       Test-SPContentDatabase [-Id
Cmdlet        Upgrade-SPContentDatabase    Upgrade-SPContentDatabase [

We’ll explore how to use the first six cmdlets here.

Getting a SharePoint 2010 Content Database

The Get-SPContentDatabase cmdlet is used to return one or more content databases in SharePoint 2010. You can retrieve a specific content database, a content database based on a site collection, or a content database from a specified web application.

Let’s start by retrieving all available content databases:

PS > Get-SPContentDatabase

Id               : 96dfa348-42df-4e9b-bbc5-1f4e8ee1051e
Name             : WSS_Content
WebApplication   : SPWebApplication Name=SharePoint - 80
Server           : SPServer01
CurrentSiteCount : 2

To retrieve content databases for a specific site collection, use the Site parameter:

PS > Get-SPContentDatabase -Site http://SPServer01

Id               : 96dfa348-42df-4e9b-bbc5-1f4e8ee1051e
Name             : WSS_Content
WebApplication   : SPWebApplication Name=SharePoint - 80
Server           : SPServer01
CurrentSiteCount : 2

It is even possible to specify a web application and retrieve the content databases attached to it. If the web application is associated with more than one content database, all are returned.

PS > Get-SPContentDatabase -WebApplication "SharePoint - 80"

Id               : 96dfa348-42df-4e9b-bbc5-1f4e8ee1051e
Name             : WSS_Content
WebApplication   : SPWebApplication Name=SharePoint - 80
Server           : SPServer01
CurrentSiteCount : 2

Like SPSite and SPWeb, the SPContentDatabase class has a large number of properties containing rich information, which you can retrieve through the appropriate cmdlet. The Format-List cmdlet displays the information as a list. Used with the asterisk wildcard, it retrieves all properties:

PS > Get-SPContentDatabase | Format-List *

Figure 1 shows the output from this command.

Figure 1. Using Format-List to display all properties

Configuring the SharePoint 2010 Content Database

The Set-SPContentDatabase cmdlet is used to change the properties of a content database. This cmdlet allows you to change the maximum number of site collections that a content database can host, change the status of the content database, and specify the number of sites that can be created before a warning event is generated.

We’ll start with modifying the maximum number of site collections allowed. First, let’s get the current value of the MaximumSiteCount property:

PS > (Get-SPContentDatabase -Site  http://SPServer01).MaximumSiteCount
15000

Here’s how to change the value using the Set-SPContentDatabase cmdlet:

PS > Get-SPContentDatabase -Site http://SPServer01 |
>> Set-SPContentDatabase -MaxSiteCount 20000
PS > (Get-SPContentDatabase -Site http://SPServer01).MaximumSiteCount
20000

This example uses Get-SPContentDatabase to retrieve a content database, and then uses a pipeline to send the object to the Set-SPContentDatabase cmdlet. We then use the MaxSiteCount parameter and change the value to 20000, increasing it by 5,000 sites. When we check the MaximumSiteCount property, we can see that the value has been updated.

Next, let’s change the status of the content database to Offline:

PS > (Get-SPContentDatabase -Site http://SPServer01).Status
Online
PS > Get-SPContentDatabase -Site http://SPServer01 |
>> Set-SPContentDatabase -Status Offline
PS > (Get-SPContentDatabase -Site http://SPServer01).Status
Offline

In this example, we use the -Status parameter to change the status of the content database from Online to Offline. We verify that the change was made using the Get-SPContentDatabase cmdlet. It is just as simple to set the status to Online, as follows:

PS > Get-SPContentDatabase -Site http://SPServer01 |
>> Set-SPContentDatabase -Status Online

Attaching and Detaching a Content Database in SharePoint 2010

The SharePoint 2010 snap-in for Windows PowerShell offers two cmdlets that allow you to attach and detach content databases to a SharePoint 2010 farm.

To detach a content database, use the Dismount-SPContentDatabase cmdlet:

PS > Get-SPContentDatabase -Site http://SPServer01 | Dismount-SPContentDatabase

Confirm
Are you sure you want to perform this action?
Performing operation "Dismount-SPContentDatabase" on Target "WSS_Content".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?]
Help(default is "Y"): Y


					  

As you can see, Windows PowerShell displays a confirmation prompt asking if you are sure that you want to perform the action. Cmdlets that perform actions that involve a risk to the system or to user data often require a confirmation. When you type Y or just press ENTER, the action is performed. If you now try to access your content database with the Get-SPContentDatabase cmdlet, nothing will be returned, since the content database is detached from the farm.

To attach a content database to a farm in SharePoint 2010, use the Mount-SPContentDatabase cmdlet:

PS > Mount-SPContentDatabase "WSS_Content" -DatabaseServer SPServer01 '
>> -WebApplication http://SPServer01

Id                   : 96dfa348-42df-4e9b-bbc5-1f4e8ee1051e
Name                 : WSS_Content
WebApplication       : SPWebApplication Name=SharePoint - 80
Server               : SPServer01
CurrentSiteCount     : 2

Creating a New Content Database

Windows PowerShell lets you create new content databases with the New-SPContentDatabase cmdlet. The cmdlet has two required parameters:

  • The Name parameter sets the name of the content database.

  • The WebApplication parameter specifies to which web application in SharePoint 2010 the new content database should be attached.

The following example creates a new content database called MyContentDB and attaches it to a web application.

PS > New-SPContentDatabase -Name "MyContentDB" '
>> -WebApplication  http://SPServer01:5077

Id                : 8975393a-cc0a-4d68-ab69-078b1b870904
Name              : MyContentDB
WebApplication    : SPWebApplication Name=My WebApplication
Server            : SPServer01
CurrentSiteCount  : 0

Removing a Content Database in SharePoint 2010

To remove a content database with Windows PowerShell, use the Remove-SPContentDatabase cmdlet:

PS > Get-SPContentDatabase -Identity "MyContentDB" | Remove-SPContentDatabase

Confirm
Are you sure you want to perform this action?
Performing operation "Remove-SPContentDatabase" on Target "MyContentDB".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"): Y

Confirm
Removing 'MyContentDB' will permananetly delete the SQL database, permanently deleting all content stored within it.
Use Dismount-SPContentDatabase if you do not want to delete the SQL database.
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"): Y


					  

In this example, we use Get-SPContentDatabase to retrieve a content database and a pipeline to send the current object to the Remove-SPContentDatabase cmdlet. As with the Dismount-SPContentDatabase cmdlet, when you use Remove-SPContentDatabase, Windows PowerShell asks for confirmation before performing the operation.

Other -----------------
- BizTalk 2010 : ASDK SQL adapter examples (part 4) - Composite Operations
- BizTalk 2010 : ASDK SQL adapter examples (part 3) - Query notification and multiple result sets
- BizTalk 2010 : ASDK SQL adapter examples (part 2) - Select, Table Valued Function, and Execute Reader
- BizTalk 2010 : ASDK SQL adapter examples (part 1) - TypedPolling and debatching
- Microsoft Dynamics AX 2009 : Integration with Microsoft Office - Sending email using Outlook
- Microsoft Dynamics AX 2009 : Integration with Microsoft Office - Exporting data to Microsoft Project
- Microsoft Content Management Server : The ASP.NET Stager Application (part 3) - Staging Attachments
- Microsoft Content Management Server : The ASP.NET Stager Application (part 2) - Staging Channels and Postings
- Microsoft Content Management Server : The ASP.NET Stager Application (part 1) - The DotNetSiteStager Project, Recording Messages to a Log File
- Microsoft Content Management Server : Staging Static Pages - Site Stager in Brief
 
 
Video tutorials
- How To Install Windows 8 On VMware Workstation 9

- How To Install Windows 8

- How To Install Windows Server 2012

- How To Disable Windows 8 Metro UI

- How To Change Account Picture In Windows 8

- How To Unlock Administrator Account in Windows 8

- How To Restart, Log Off And Shutdown Windows 8

- How To Login To Skype Using A Microsoft Account

- How To Enable Aero Glass Effect In Windows 8

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
programming4us programming4us
 
programming4us
Girls
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone