Thursday, 3 April 2014

Get MetaData of pages

this poweshell script will iterate over all the pages in a pages library find ones that have a department field with a value that contains the word Information, then write them to the screen. because i use write-output instead of write-host you can pipe them to a text file like I show in the second example
<#
.Synopsis
   List IT Policy & Procedure MetaData
.DESCRIPTION
   Script used to list Information and Technology Policies and procedures
.EXAMPLE
   Get-spmPolicyProcedureMetaData -WebAddress http://YourSite/PolicyProcedure
.EXAMPLE
   Get-spmPolicyProcedureMetaData -WebAddress http://YourSite/PolicyProcedure | Out-File c:\steve1.txt
#>
function Get-spmPolicyProcedureMetaData
{
    Param
    (
        # Web address contianing policies and procedures 'http://yoursite/PolicyProcedure'
            [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$False,
                   Position=0)]
        [string]
        $WebAddress
    )
      Begin
      {
            $web = get-spweb $WebAddress
            $pageLib = $web.Lists["Pages"]
      }
      Process
      {
            $PageLib.Items | %{
                  $page = $_
                  if($page["Department"] -like '*Information*'){
                        $pageName = "Page Name = " + $page.Name
                        Write-Output $pageName
                       
                        $dept = "Department = " + $page["Department"].trimstart("23;#")
                        Write-OutPut $dept
                       
                        $eff = "EFF Date = " + $page["Published Effective Date"].trimstart("string;#")
                        Write-Output $eff
                       
                        $cr = "Council Resolution Number = " + $page["Council Resolution Number"]
                        Write-Output $cr
                       
                        $desc = "Description = " + $page["Comments"]
                        Write-Output $desc
                        Write-Output ""
                  }
            }    
      }
      End
      {
            $web.Dispose()
      }

}

you can run this by entering

PS C:\dev> . . /filename.ps1
PS C:\dev> Get-spmPolicyProcedure -webaddress http://yoursite/yourweb