-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDelete-ListItemInView.ps1
More file actions
70 lines (62 loc) · 1.61 KB
/
Delete-ListItemInView.ps1
File metadata and controls
70 lines (62 loc) · 1.61 KB
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
<# This script requires SharePoint Server PowerShell Commands #>
param ([Switch]$WhatIf)
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
function Delete-ListItemInView
{
[cmdletbinding()]
param
(
[parameter(Mandatory=$true)][Microsoft.SharePoint.SPList]$List,
[parameter(Mandatory=$true)][Microsoft.SharePoint.SPView]$View
)
begin
{
}
process
{
$items = $list.GetItems($view)
$tempItems = @()
$items | % { $tempItems += $_ }
Write-Output "Deleting $($items.Count) items from $($View.Title)..."
foreach( $item in $tempItems )
{
if( -not $WhatIf.IsPresent )
{
$item.Delete()
}
else
{
Write-Output "Would have deleted item with ID: $($item.Id) and Title: $($item.Name)"
}
}
}
end
{
}
}
#note that the view page or view limit DOES affect the items deleted
$webUrl = "http://sp16.dev.local/sites/team"
$listTitle = "LargeList"
$viewTitle = "All Items"
if( $web = Get-SPWeb -Identity $webUrl -ErrorAction SilentlyContinue )
{
if( $list = $web.Lists.TryGetList( $listTitle ) )
{
if( $view = $list.Views | ? Title -eq $viewTitle )
{
Delete-ListItemInView -List $list -View $view
}
else
{
Write-Host "View not found" -ForegroundColor Red
}
}
else
{
Write-Host "List not found" -ForegroundColor Red
}
}
else
{
Write-Host "Web not found" -ForegroundColor Red
}