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:

http://blogs.msdn.com/joelo/archive/2007/03/19/solutions-information-policies-compliance-and-auditing.aspx

http://msdn2.microsoft.com/en-us/library/aa981572.aspx

http://msdn2.microsoft.com/en-us/library/microsoft.office.recordsmanagement.informationpolicy.policycollection.add.aspx

Some more links that you may be interested in (not related to policy feature installation): 

Installing and uninstalling features using stsadm.exe:

http://msdn2.microsoft.com/en-us/library/ms442691.aspx

How to create a simple feature:

http://msdn2.microsoft.com/en-us/library/ms475286.aspx

Leave a Reply