-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathDisable-AudienceTargetingOnList.ps1
84 lines (75 loc) · 2.59 KB
/
Disable-AudienceTargetingOnList.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<#
.SYNOPSIS
Disables audience targeting on a SharePoint list or library.
.DESCRIPTION
Disables audience targeting on a SharePoint list or library.
This will delete the audience targeting column from the list. All information contained in that column, will be lost!
.NOTES
File Name: Disable-AudienceTargetingOnList.ps1
Author : Bart Kuppens
Version : 1.0
.PARAMETER Web
Specifies the URL for the web where the library is located.
.PARAMETER ListName
Specifies the name of the list where you want to disable audience targeting.
.EXAMPLE
PS > .\Disable-AudienceTargeting.ps1 -Web http://teamsites.westeros.local -ListName Documents
Description
-----------
Disables audience targeting on the "Documents" library on http://teamsites.westeros.local
#>
[CmdletBinding()]
param(
[parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL for the web where the library is located.")]
[string]$Web,
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the list where you want to enable audience targeting.")]
[string]$ListName
)
# Load the SharePoint PowerShell snapin if needed
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "Loading the SharePoint PowerShell snapin..."
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$SPWeb = Get-SPWeb $Web -EA SilentlyContinue
if ($SPWeb -eq $null)
{
Write-Error "$Web is not a valid SharePoint Web"
}
else
{
Try
{
$fieldID = "61cbb965-1e04-4273-b658-eedaa662f48d"
[Guid]$AudFieldID = New-Object System.Guid($fieldID)
$list = $SPWeb.Lists[$ListName]
if ($list -ne $null)
{
# Check if audience targeting is enabled on this list.
$audField = $list.Fields[$AudFieldID]
if ($audField -ne $null)
{
# It's enabled, disable it.
$list.Fields.Delete($audField.InternalName);
$list.Update()
Write-Host -ForegroundColor Green "Audience targeting is succesfully disabled on '$ListName'"
}
else
{
Write-Host -ForegroundColor Yellow "Audience targeting is not enabled on '$ListName'"
}
}
else
{
Write-Host "The list with the name $ListName was not found on $($SPWeb.Url)"
}
}
catch
{
Write-Error $_.Exception
}
finally
{
$SPWeb.Dispose()
}
}