Archive | PowerShell RSS for this section

Sharepoint Power Shell Create a Site Collection in a Specific Data Base

By default, Site collections are created on the web application database. If you want to create a Site Collection in a diferent database, you can use the following Script:

#Create the Database

New-SPContentDatabase -Name New_Content_DB  -WebApplication http://myWebApplication

#Create the Site Collection

New-SPSite http://myWebApplication/newSite -OwnerAlias <owner account name including domain name e.g.domain\username> -ContentDatabase New_Content_DB -Name <Name of your site collection> -Description <Description of site collection> -Template “STS#0”


You should also configure your WebApplication Paths to be able to create your site collection in a specific url.


Sharepoint Power Shell Add Nodes to Quick Launch Navigation

This script will add all Site subSites to QuickLaunch Navigation, in the "Sites" node.

$siteUrl = "http://localhost"
$spWeb = Get-SPWeb $siteUrl -ErrorAction Stop
$quickLaunch = $spWeb.navigation.quicklaunch
$sitesGroup = $quickLaunch | where { $_.Title -eq "<strong>Sites</strong>" }

foreach($subSite in $spWeb.Webs)
 $node = New-Object -TypeName Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList $subSite.Title , $subSite.Url


Sharepoint Power Shell include lists in Quick Launch Navigation

The next PowerShell Script will be usefull to include all web lists in Quick Launch Navigation:

$site = Get-SPSite  http://localhost
#Walk through each web/site in the site collection
$site | Get-SPWeb | ForEach-Object {
foreach($list in $_.Lists)
         $list.OnQuickLaunch = "true"
         #Update the list

#Dispose of the site object

How to change Sharepoint 2010 MasterPage with Power Shell

To change a site master page with power Shell, you can run the above script (with admin priviledges), changing the bold settings (MasterUrl is the system master page):

$web = Get-SPWeb <strong>http://intranet</strong>

$web.CustomMasterUrl = "/_catalogs/masterpage/<strong>v4.master</strong>"

$web.MasterUrl = "/_catalogs/masterpage/<strong>v4.master</strong>"