Tag Archives: PowerShell

How to tips for SharePoint 2010 or Sharepoint 2013

This is more of a “Note to Self” entry with four quick tips I found myself looking for quite often in the last couple of weeks.

If you happen to have stumbled on this post, you probably are looking for the same thing, so Enjoy!

  • How to retrieve a list of master pages for all sites in a web application
  • How to retrieve the SharePoint connection sting, which will also list the name of the configuration database associated with your farm. Extremely helpful if you have more than one configuration database setting in the same SharePoint environment, which happens not to be yours!
  • How to reset the SharePoint passphrase for SharePoint, since you can’t retrieve it in PowerShell [to my knowledge]
  • How to grant site collection administrator right to all site collections

So here we go:

How to retrieve a list of master pages for all sites in a web application

Run this PowerShell command on the SharePoint application server

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get All site collections

$SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All

#Loop through all site collections

foreach($Site in $SiteCollections)

{

#Loop throuh all Sub Sites

foreach($Web in $Site.AllWebs)

{

$MasterPage = $Web.GetFile($Web.MasterUrl);

$MasterPage.Name  +” : ” +$Web.Url

}

}

How to retrieve the SharePoint connection string, which will also list the name of the configuration database associated with your farm

From the SharePoint application server

  • Open regedit [Start > Run > “regedit”]
  • Navigate to [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure\ConfigDB]
  • Open the [dsn] key.
  • It should look something like this.
  • Data Source=sp2010srv;Initial Catalog=SharePoint_Config;Integrated Security=True;Enlist=False;Connect Timeout

How to reset the SharePoint passphrase for SharePoint, since you can’t retrieve it in PowerShell

Run the following PowerShell from the SharePoint application server

  • Enter the following prompt: $passphrase = ConvertTo-SecureString -asPlainText –Force
  • Input the new passphrase and hit enter
  • Enter this at the PowerShell prompt: Set-SPPassPhrase -PassPhrase $passphrase -Confirm
  • You will be asked to confirm the passphrase by re-entering it
  • Re-enter the passphrase and hit enter
  • You will be asked if you are sure that you want to perform this action. Type Y for yes and hit enter
  • Your farm passphrase is now reset

How to grant site collection administrator right to all site collections

Run the following PowerShell from the SharePoint application server

$scadmin = “domain\user”

$Sites = Get-SPsite

foreach ($site in $Sites) {

Set-SPSite -Identity $site -SecondaryOwnerAlias $scadmin

}

List Site Templates and IDs in SharePoint 2010 Using Windows PowerShell

One of the main checkpoints you will have to worry about as you upgrade or migrate SharePoint sites across farms or versions are custom site templates and how they are handled during migrations. You may upgrade or migrate custom site templates as is or you may elect to re-template site templates. A perfect place to start would be to know what custom site templates you have. So I did some research and finally stumbled upon a couple of scripts that I want to share with you. These scripts will help you:

  • List all site collections within a web application <– This will give us a better understanding of the total number of sites we may consider for migrations
Get-SPWebApplication “http://WebAppAddress“| Get-SPSite -limit ALL|Get-SPWeb -limit ALL|Select-Object Title,Url
  • List all site templates and template IDs for a given web application <– So we end up knowing what is standard and what is custom
$webapp = Get-SPWebApplication -identity http://WebAppAddress/
$webtem = Get-spwebtemplate
foreach ($site in $webapp.Sites)
{
 $spweb = get-spweb $site.URL
 write-host “Site URL: ” $site.URL
 write-host “Web Template: ” $spweb.WebTemplate
 write-host “WebTemplateID: ” $spweb.WebTemplateID
 write-host “————————————-”
}
  • List site template and site ID for a given site <– If there is a specific site we want to migrate and are interested in knowing what template it was created from
$web = Get-SPWeb http://webapp/sites/site/subsiteaddress
write-host “Web Template:” $web.WebTemplate ” | Web Template ID:” $web.WebTemplateId
$web.Dispose()
  • In general a list of all site templates available <– If you just want to see what site templates you have
 Get-SPWebTemplate | Sort-Object “Name”

I’ve recorded a short video to demonstrate the above.

Video length: 3:56

Ghazwan Khairi

SharePoint Quester

Display Lists & Libraries That Use a Specific Content Type in SharePoint 2010

SharePoint content types encapsulate data requirements, enable content standardization, and are independent of file formats which makes them popular to use across SharePoint. Fast forward to a few hundred content types used within a large SharePoint environment and you’ll soon need to pay attention to managing these content types and answering question such as how many custom content types do we have and where are they being used.

A specific scenario this post addresses is the need to report on a specific content type use within a site collection. The video and script below highlight the process you’d need to take to generate such a report.

Video length: 2:24 min

To list a specific content type usage within a site collection copy and paste the following script into the SharePoint 2010 Management Shell.

Note: Two things to change: 1. The site collection address and 2. The content type name

 $webs = get-spsite http://sharepoint2010/sites/portal14| get-spwebforeach ($web in $webs)

foreach ($lst in $web.lists)  
{    
foreach ($ctype in $lst.ContentTypes)    
{      
if ($ctype.Name -eq “Document”)      
{ $lst.DefaultViewUrl
}   

}  
$web.Dispose()
}

 

List All Web Parts in a SharePoint 2010 Site Collection Using Windows PowerShell

I won’t make this overly complex, but if your organization is rapidly growing with SharePoint and you, farm admin, or your site collection administrators, or even your site owners are all super excited about SharePoint’s capabilities and you are provisioning sites or pages to justify the ever growing demands of your business, then you probably are adding hundreds of web parts to your sites and pages.

In most cases, these web parts are simply what shipped with the product and what gets placed on the sites once you provision them such as ‘Shared Documents’ or ‘Announcements’. In other cases, they maybe web parts developed in house by your development team to meet a specific demand such as ‘a moving average chard web part’ or even purchased from a third party vendor like Quest Software or Bamboo Solutions.

In any case, as your SharePoint succeeds and grows, and again, as you drop more web parts to your pages, the need to control and understand were these web parts are becomes super important. You will want to know which web parts are open and which ones are closed, which ones are used and which ones are not, which ones are affecting load time on pages and which ones are causing errors.

The video below captures the steps involved in executing a Windows PowerShell script that will loop through pages on publishing and non-publishing sites, finds all web parts, and outputs the result to a grid view.

Video length: 2:27

Use the below script to list all web parts in a site collection. The script loops through all pages, publishing and non-publishing sites, finds all web parts, and displays them on a grid view.

Note: Make sure you change the URL at the bottom of the script to your site collection URL.

 function enumerateWebParts($Url) {
    $site = new-object Microsoft.SharePoint.SPSite $Url    foreach($web in $site.AllWebs) {
        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
            $pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
            $pages = $pWeb.PagesList
            foreach ($item in $pages.Items) {
                $fileUrl = $webUrl + “/” + $item.File.Url
                $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
                $wps = $manager.webparts
                $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}
            }
        }
        else {
            $pages = $null
            $pages = $web.Lists[“Site Pages”]            if ($pages) {                foreach ($item in $pages.Items) {
                    $fileUrl = $webUrl + “/” + $item.File.Url
                    $manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
                    $wps = $manager.webparts
                    $wps | select-object @{Expression={$pWeb.Url};Label=”Web URL”},@{Expression={$fileUrl};Label=”Page URL”}, DisplayTitle, IsVisible, @{Expression={$_.GetType().ToString()};Label=”Type”}
                }
            }
            else {
            }
        }        Write-Host “… completed processing” $web
    }
}$row = enumerateWebParts(‘http://sharepoint2010/sites/spquester’)
$row | Out-GridView

If the Integrated Script Editor (ISE) is not installed, execute the following script then go back to the script above and execute it.

Import-Module ServerManagerAdd-WindowsFeature PowerShell-ISE

Removing User Alerts from a Web Application in SharePoint 2010 Using Windows PowerShell

Video length: 2:05

Video description: This video walks through the process of removing a specific user alerts from a web application in SharePoint 2010 using Windows PowerShell

Read more »

Reporting on Site Alerts in SharePoint 2010 Using Windows PowerShell

Video Length: 1:21

Video Description: This video walks through reporting on site alerts in SharePoint 2010 using Windows PowerShell. The script provided can be used against sites or site collections, the results of the script will present the list name, alert title, and the subscribed user all followed by a liner for easy reading.

Read more »

Reporting on Activated Site Collection Features in SharePoint 2010 Using Windows PowerShell

Video length: 2:53

Video description: This video walks through the process of generating a report on all activated site collection features in SharePoint 2010 using Windows PowerShell. The video also shows how you can report against active features at the web application level as well as reporting on a specific feature to see if it has been activated or not at the site collection level.

Read more »

Reporting SharePoint 2010 Site Collections Storage and Quota using Windows PowerShell

Video length: 2:47

Video description: This video walks through the process of reporting SharePoint 2010 site collections storage and quota using Windows PowerShell

Read more »

Creating Multiple Site Collections in SharePoint 2010 using Windows PowerShell

Video length: 4:03

Video description: This video walks through the process of creating multiple site collections with multiple content database names in SharePoint 2010 using Windows PowerShell.

Read more »

Automating SharePoint 2010 Backup Using Windows PowerShell

Video length: 5:31

Video description: This video walks through the process of using Windows PowerShell and Windows Task Scheduler to automate the nightly backup of a SharePoint 2010 farm.

Detailed video steps below:

Read more »