SharePoint: This is Why I Loved Powershell Today


So just at the moment I’m developing some custom policy resources for an Information Management retention/expiration solution for a client, and in the midst of testing I discover that some content items aren’t expiring as they should.

Why I Loved Powershell Today #1

I needed to check the values of some columns on content items which weren’t expiring, columns hidden or otherwise not shown in the UI…

cls
Add-PSSnapin microsoft.sharepoint.powershell -ea SilentlyContinue

$w = get-spweb "http://sp/sites/team"
$i = $w.GetFile("Retained Documents/Bobs Document.docx").Item

$i.Fields | ? {
    -not $_.Hidden -or (@("Exempt from Policy", "Original Expiration Date") -contains $_.Title)
} | % {
    "$($_.Title) [$($_.InternalName)] = $($i[$_.InternalName])"
}

$w.Dispose()
#ILovedPowershellToday 1
#ILovedPowershellToday 1

Why I Loved Powershell Today #2

I needed to check that my custom policy resources, were actually really really registed in the farm…

cls
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Policy")
'- List Policy Features and Resources'
[Microsoft.Office.RecordsManagement.InformationPolicy.PolicyCatalog]::FeatureList | % {
    write-host "Feature: $($_.Id)"
    $_.ResourceList | format-table Id, Type, Name -auto
    write-host "-----------------------------------------------------------------------"
}
#ILovedPowershellToday 2
#ILovedPowershellToday 2

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.