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”

Reference: http://technet.microsoft.com/en-us/library/ff607937.aspx

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

http://technet.microsoft.com/en-us/library/cc261845.aspx#section1

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
 $sitesGroup.Children.AddAsLast($node)
 $spWeb.Update()

}
$spWeb.Dispose()

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
         $list.Update()
        }
}

#Dispose of the site object
$site.Dispose()

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>"

$web.Update()