August 28, 2013

List all pages using specific Page Layout

clear
   1:  Add-PsSnapin Microsoft.SharePoint.PowerShell
   2:  filter Get-PublishingPages
   3:  {
   4:                  $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
   5:      $query = new-object Microsoft.SharePoint.SPQuery
   6:                  $query.Query = "<Where><In><FieldRef Name='PublishingPageLayout' /><Values><Value Type='URL'>/_catalogs/masterpage/<Layout1.aspx></Value><Value Type='URL'>/_catalogs/masterpage/<Layout2.aspx></Value><Value Type='URL'>/_catalogs/masterpage/<Layout3.aspx></Value></Values></In></Where>"
   7:     
   8:                  $query.ViewAttributes = "Scope='Recursive'"
   9:      $pubweb.GetPublishingPages($query)   
  10:  }
  11:   
  12:  $str = Read-Host "Enter Site URL: "
  13:   
  14:  if($str -eq $null )
  15:  {
  16:                  Write-Host "Enter a valid URL"
  17:                  return
  18:  }
  19:   
  20:  $site = Get-SPSite -Identity $str
  21:  if($site -eq $null)
  22:  {
  23:                  Write-Host "Enter a valid URL"
  24:                  return
  25:  }
  26:   
  27:  $allweb = $site.Allwebs
  28:  foreach($web in $allweb )
  29:  {
  30:      $web | Get-PublishingPages | select Uri, Title, @{Name='PageLayout';Expression={$_.Layout.ServerRelativeUrl}}| Format-List
  31:  }

If you have any questions you can reach out our SharePoint Consulting team here.

Powershell Script Block To List ALL/Unused/Used Content Database


   1:  #Import Localized Data
   2:  #Import-LocalizedData -BindingVariable Message
   3:  Add-PsSnapin Microsoft.SharePoint.PowerShell
   4:  #This function is used to get standard content database list for Get-OSCContentDatabase
   5:  function Export-OSCContentDatabase
   6:  {
   7:  PARAM
   8:      (   
   9:          $ContentDatabases
  10:      )
  11:          $ContentDatabases | Select-Object -Property `
  12:                              @{Name="Url";Expression={
  13:                                  $_.WebApplication.Url
  14:                                                     }},`
  15:                              @{Name="ID";Expression={
  16:                                   $_.Id
  17:                                                     }},`
  18:                              @{Name="Name";Expression={
  19:                                   $_.Name
  20:                                                      }},`
  21:                              @{Name="WebApplication";Expression={
  22:                                   $_.WebApplication
  23:                                                      }},`
  24:                              @{Name="Server";Expression={
  25:                                   $_.Server
  26:                                                      }},`
  27:                              @{Name="CurrentSiteCount";Expression={
  28:                                   $_.CurrentSiteCount
  29:                                                      }},`
  30:                              @{Name="Status";Expression={
  31:                                   $_.Status
  32:                                   }} | Sort-Object -Property Name
  33:  }
  34:   
  35:  function Get-OSCContentDatabase
  36:  {          
  37:      [CmdletBinding(DefaultParameterSetName="UnUsedDatabase")]
  38:      PARAM
  39:          (
  40:              [Parameter(Mandatory=$false,Position=0,ParameterSetName='UsedDatabase')]
  41:              [switch]$UsedDatabase,
  42:              [Parameter(Mandatory=$false,Position=0,ParameterSetName='UnUsedDatabase')]
  43:              [switch]$UnUsedDatabase
  44:           )
  45:              [array]$arrContentDB = @()
  46:              try
  47:                  {
  48:                       Get-SPWebApplication -IncludeCentralAdministration | ForEach-Object{
  49:                       $arrContentDB += $_.ContentDatabases
  50:                                  }
  51:                  }
  52:                  catch [Exception]
  53:                  {
  54:                       #Catch and throw the terminating exception
  55:                       throw $Error[0].Exception.Message
  56:                  }
  57:                 
  58:                  #Check if content databases exist
  59:                  if($arrContentDB.Count -eq 0)
  60:                  {
  61:                       Write-Error $Message.NoContentDB
  62:                       return $null
  63:                  }
  64:                 
  65:                  $scriptContentDBOutput = @()
  66:                  $scriptContentDBOutput += Export-OSCContentDatabase $arrContentDB
  67:                 
  68:                  #List the content databases which are in use currently
  69:                  if($UsedDatabase)
  70:                  {
  71:                        Write-Host $Message.UsedDatabase
  72:                        $scriptContentDBOutput = $scriptContentDBOutput | Where-Object{$_.Status -eq "Online"}
  73:                        if($scriptContentDBOutput.Count -eq 0)
  74:                         {
  75:                            Write-Host $Message.ZeroUsedContentDB
  76:                            return $null
  77:                         }
  78:                  }
  79:                  #List the content databases which are not in use currently
  80:                  elseif($UnUsedDatabase)
  81:                  {
  82:                          Write-Host $Message.UnUsedDatabase
  83:                          $scriptContentDBOutput = $scriptContentDBOutput | Where-Object{$_.Status -ne "Online"}
  84:                          if($scriptContentDBOutput.Count -eq 0)
  85:                              {
  86:                                Write-Host $Message.ZeroUnusedContentDB
  87:                                return $null
  88:                               }
  89:                  }
  90:                  #List all content databases
  91:                  else
  92:                  {
  93:                          Write-Host $Message.AllDatabase
  94:                          if($scriptContentDBOutput.Count -eq 0)
  95:                            {
  96:                                Write-Host $Message.ZeroContentDB
  97:                                return $null
  98:                            }
  99:                  }
 100:                 
 101:                  $scriptContentDBOutput
 102:  }
 103:   
 104:  ##Uncomment Following Line to List Out All Content Database
 105:  Get-OSCContentDatabase
 106:   
 107:  ##Uncomment Following Line to List the content databases which are in use currently.
 108:  Get-OSCContentDatabase -UsedDatabase
 109:   
 110:  ##Uncomment Following Line to List the content databases which are not in use currently.
 111:  Get-OSCContentDatabase -UnUsedDatabase

If you have any questions you can reach out our SharePoint Consulting team here.

Add Empty option in SharePoint drop down (Choice) column

Issue:You would like to have a blank/null option in the drop down. But SharePoint won't take SPACE as a valid option. You could specify the field to "not required" and initially it will be blank. But once some value has been specified there is no way to go back to blank. So what is the solution?
Solution:Use ASCII code 0129. It is an empty character that SharePoint will accept as a valid option but it appears empty on the drop down. To enter the character,hold down the ALT key and type the number 0129.

If you have any questions you can reach out our SharePoint Consulting team here.