param([
switch
]$help)
[
void
][System.Reflection.Assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
)
function GetHelp() {
$HelpText = @"
DESCRIPTION:
This script will remove the columns
"Barcode"
,
"Barcode Value"
and
"Exempt from Policy"
from a list. These columns are added when Barcodes are enabled
using
IRM
policy. Even after the policy
is
withdrwan these columns stay
in
the list of columns under view settings.
"@
$HelpText
}
function RahulDeleteBarcodeIRMPolicyColumns() {
write-host "This script will remove barcode related columns from your list. Before executing
this
tool make sure that you have removed the policy otherwise it
will take you to some other issues"
write-host
"Please enter your site url"
$siteURL = read-host
"Please enter your List Name"
$listName = read-host
$site = New-Object Microsoft.SharePoint.SPSite($siteURL)
$Web = $site.OpenWeb()
$web.AllowUnsafeUpdates = $
true
$listSource = $web.Lists[$listName]
$columnNames = @(
for
($i = 0; $i -lt $columnNames.Length; $i++)
{
$fieldtoBedeleted = $listSource.Fields[$columnNames[$i]]
$fieldtoBedeleted.AllowDeletion = $
$fieldtoBedeleted.Sealed = $
false
$fieldtoBedeleted.Delete()
"The columns are deleted successfully"
$site.Dispose()
$web.Dispose()
if
($help) { GetHelp; Continue }
else
{ RahulDeleteBarcodeIRMPolicyColumns }