Techbubbles

Useful PowerShell Commands in SharePoint 2010

 

Using PowerShell is very useful and powerful approach for many SharePoint activities. Microsoft officially recommends to you use PowerShell as it intended to deprecate STSADM in the future. This post explains PowerShell cmdlets(commandlets).Scripting is easier when using PowerShell, you can access every method and property of every object. You have to use right shell to write the PowerShell commands. SP2010

1. Use SharePoint 2010 Management Shell which can be found in SharePoint Products 2010 folder in your start menu.

image

2. You need to be granted appropriate permissions to run SharePoint cmdlets. Any account that want to run PowerShell cmdlets needs below settings

  • Account has to be added to the WSS_Admin_WPG local groups on all Web Front End servers. For Farm Administrator you no need to add it to the group.
  • Account must be the owner of the databases that it administer
  • Account must be domain user account and needs to be a local administrator for the SharePoint Server.

To enable accounts or security groups to be shell admins then use the below command

Add-SPShellAdmin – The Command let Add-SPShellAdmin with the parameter of –username. This will add an account or security group as shell admin to the farm.

Add-SPShellAdmin –UserName <domain\account or securitygroup>

3. To make a shell admin which can administer other databases in the farm then you need to find out the database name and then specify that name in the Add-SPShellAdmin command. To get the list of databases run below command

Get-SpDatabase

To pass the results of above results to the shell admin command, use a pipeline between commands the command looks as below

Get-SpDatabase | Add-SPShellAdmin –UserName <domain\account or securitygroup>

4. Get-SpShellAdmin lists all shell admins available for the SharePoint implementation.

5. If you wanted to add a user as a Shell admin for one database then use the below command

Get-SpDatabase | Where-Object {$_.Name –eq  “WSS_Content”} | Add-SpShellAdmin –UserName

5. PowerShell Cmdlet structure looks as below

Get-SPWeb  used to retrieve all SharePoint sites in a site collection

new-spsite

Set-SpList

PowerShell is not case-sensitive, Cmdlets start with Get are mostly used to retrieve information.

6. To list all PowerShell commands that contain SP-Web, use the below command

Get-Command *-SpWeb

image

  • To list all cmdlets available in PowerShell

Get-Command

 

7. Creating a new sub site with  PowerShell

New-SPWeb –URL http://spf2/subsite

8. Inline help using the –? switch

image

9. If you want to see list of properties and methods for the SPWebApplication

Get-SPWebApplication | Get-Member

Get-Member cmdlet lets you see the properties and methods of an object.

10. PowerShell Commands that use Filters, the below command returns all web applications that have a maximum upload size greater than 50 MB.

Get-SPWebApplication | Where-Object {$_.MaximumFileSize –gt 50 }

11. Pipeline Get-Spsite into Set-SPSite , Below command specifies the web application where object is any web application name ends with an “-80” using a comparison operator like

Get-SpSite | Where-Object {$_.WebApplication –like “* -80” }

Using the same above criteria but set properties on the site collections that are returned

Get-SpSite | Where-Object {$_.WebApplication –like “* -80” }  | Set-SPSite –MaxSize 200MB –WarningSize 175MB


Share this post :





Related Posts:

%d bloggers like this: