A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Saturday, September 8, 2007

Using powershell to add a policy feature to the collection

Following is the script to add a policy to the feature collection. This script will add a policy to the Records Management's feature collection. 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Policy")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$Url = "http://server/marketing"
$site = new-Object Microsoft.SharePoint.SPSite($Url)
#add policy to the collection
$xml = [System.IO.File]::ReadAllText("C:My Documentsfeature.xml")
[Microsoft.Office.RecordsManagement.InformationPolicy.PolicyFeatureCollection]::Add($xml)
 Similarly, to delete the policy, use following script:
[Microsoft.Office.RecordsManagement.InformationPolicy.PolicyFeatureCollection]::Delete("MarketingPolicy")
feature.xml will contain the following:
<PolicyFeature
  id="MarketingPolicy" xmlns="urn:schemas-microsoft-com:office:server:policy">
 <Name>Marketing Policy</Name>
 <Description>Marketing Policy</Description>
 <Publisher>ABC</Publisher>
 <AssemblyName>MarketingPolicy,Version=1.0.0.0,Culture=neutral,PublicKeyToken=a0231d53df8a952</AssemblyName>
 <ClassName>Marketing</ClassName>
</PolicyFeature>
Add your own assembly's information in this file (feature.xml).
See following links if you want to learn more about policies, adding policies, records management, etc:
Some more links that you may be interested in (not related to policy feature installation): 
Installing and uninstalling features using stsadm.exe:
How to create a simple feature: