Not a Coder — Can Anyone Explain Line-by-Line what this does?

Business need to deleted records en mass from Sharepoint (100 max deletion via manual process). I came across this blog post:

https://blogs.msdn.microsoft.com/ahmedamin/2017/08/03/bulk-delete-sharepoint-items-in-a-large-list-using-powershell/

With the code below:

Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue

$web = get-spweb “Site URL”

$list = $web.lists[“Library Title”]

$query = New-Object Microsoft.SharePoint.SPQuery

$query.ViewAttributes = “Scope=’Recursive'”

$query.RowLimit = 1000

$query.ViewFields = “<FieldRef Name=’ID’/>”

$query.ViewFieldsOnly = $true

do

{$listItems = $list.GetItems($query)

$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

foreach($item in $listItems)

{Write-Host “Deleting Item – $($item.Id)”

 $list.GetItemById($item.Id).delete()}} 

while ($query.ListItemCollectionPosition -ne $null)

I’m not a coder, but I get in general how logic works, etc. I am not sure what these commands do. I would ideally be able to take this and maybe apply some filtering criteria to choose which items to delete. Completely 0 experience with Powershell. Any help?

Edit: Sorry for the formatting, don’t know how to fix.

submitted by /u/Reddits_For_NBA
[link] [comments]

Leave a Reply