About Me

My photo
a Dynamic and Energetic guy.....

Tuesday, January 29, 2013

PowerShell Command Builder

I got a nice tool that can create "Windows Power Shell Commands" dynamically.
Go here


Simple Power shell command generation screen,
"Create -SPSite"


"Add -SPSolution"

Simple...


Sunday, January 27, 2013

Apply MasterPage to all Site Collections Using PowerShell Commands

------------------------ Set Master Page ----------------------------- 
foreach ($site in get-spsite -url http://spsvr*) {
     $web = Get-SPWeb $site
     $web.CustomMasterUrl = "/_catalogs/masterpage/my_v4.master" 
     $web.Update()
}
 
------------------------ Using Other Method --------------------------
 
foreach ($site in Get-SPSite)
{
 foreach ($web in $Site.AllWebs)
 {
  $web.MasterUrl  = "/_catalogs/masterpage/my_v4.master";
  $web.CustomMasterUrl = "/_catalogs/masterpage/my_v4.master";  
  $web.update()
 }
} 
 
---------------------- Set Master Page For Web Application ------------
----------------------------------------------------------------------- 
#Enter a web application, get all the site collections in the web app
Add-PsSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global

$web = Get-SPWeb 'http://spsvr:1111/'
#$web.CustomMasterUrl = "/_catalogs/masterpage/v4_TG.master"
$web.MasterUrl = "/_catalogs/masterpage/v4_TG.master"
$web.Update()


--------------------- Set Master Page For All Subsites --------------
----------------------------------------------------------------------
#Enter a web application, get all the site collections in the web app
Add-PsSnapin Microsoft.SharePoint.PowerShell

Start-SPAssignment -Global
$site = Get-SPSite 'http://spsvr:1111'
$topWeb = Get-SPWeb $site.Url
$site | Get-SPWeb -limit all | ForEach-Object 
{if (($_.WebTemplate -ne "SRCHCEN") -and ($_.WebTemplate -ne "SRCHCENTERLITE") -and ($_.WebTemplate -ne "SRCHCENTERFAST")) {$_.CustomMasterUrl = $topWeb.CustomMasterUrl;$_.AllProperties["__InheritsCustomMasterUrl"] = "True";$_.MasterUrl = $topWeb.MasterUrl;$_.AllProperties["__InheritsMasterUrl"] = "True";$_.AlternateCssUrl = $topWeb.AlternateCssUrl;$_.AllProperties["__InheritsAlternateCssUrl"] = "True";$_.Update();}}
Stop-SPAssignment -Global

My Masters