Archive for the ‘PowerShell’ Category

PowerShell: Apply Master Page and Logo to Team Sites

July 7, 2015 Leave a comment

Apply custom master page and Logo to site and all its subsites where site is Team Site

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
$site = Get-SPSite yoursitecollectionurl
foreach ($web in $site.AllWebs)
 $web.MasterUrl = $site.RootWeb.ServerRelativeUrl + "/pathtoyourmasterpage.master";
 $web.CustomMasterUrl = $site.RootWeb.ServerRelativeUrl + "/pathtoyourmasterpage.master";
 $web.SiteLogoUrl = $site.RootWeb.ServerRelativeUrl + "/pathtoyourlogo.gif";
 Write-Host $web.Url $web.MasterUrl $web.CustomMasterUrl;
write-host "completed"

Happy SharePointing !

How To: Delete List Template using PowerShell

July 11, 2013 1 comment


One of my friend was looking for solution to remove list template of custom list using Power Shell.

So, I’ve created quick Power Shell script for the same as below and that worked perfect:

Power Shell Script:

$site = Get-SPSite http://site
$web = $site.OpenWeb()
$spFolder = $web.getfolder("_catalogs/lt")
#$spfileCollection = $spfolder.Files

$spfolder.Files | %{
 if ($_.Name -eq "templatename.stp") {
write-output "found"

Happy SharePointing !!!

Start Application Pool automatically from IIS using PowerShell

October 4, 2012 Leave a comment


From last some days, we were facing some issue where our server automatically stop some application pool from IIS when something deploy on server.

We need to start it manually from IIS. but we need to fix it.

And my colleague(Jay Mehta) gave us very good solution with PowerShell script.


Import-Module WebAdministration
cd IIS:/AppPools
$ApplicationPools = dir
foreach ($item in $ApplicationPools)
    $ApplicationPoolName = $item.Name
    $ApplicationPoolStatus = Get-WebAppPoolState $ApplicationPoolName
    if($ApplicationPoolStatus.Value -eq "Stopped")
         #Write-Host $ApplicationPoolName --> $ApplicationPoolStatus.Value
         Write-Host $ApplicationPoolName "found stopped."
         Start-WebAppPool -Name $ApplicationPoolName
         Write-Host $ApplicationPoolName "started."

This scripts will check whether any application pool inside IIS is stopped. If it found it will start that application pool.

then, we have created task scheduler which runs automatically in every 30 mins  and attached the above script.

Thanks to Jay Mehta for sharing such nice code / information.

Happy Coding !!!