Date and Month display

Sunday, February 23, 2020

Delete/ Recycle documents from SharePoint Site

<#
******-----------------------------------------------------------------------******
Author          -> Shiv Mangal Singh
Date            -> 20th February - 2020
Description     -> Delete and recycle the documents in SharePoint Site
$web =    "Site Url"

******-----------------------------------------------------------------------******
  #>
Add-PSSnapin Microsoft.SharePoint.PowerShell

# Get Site name 
$web =Get-SPWeb "https://contoso.microsoft.com/sites/abc"

# Get document librray/ list name
$list = $web.GetList("https://contoso.microsoft.com/sites/abc/test/")

$spQuery = New-Object Microsoft.SharePoint.SPQuery;

# Pass the document ID in below camel Query ex-->  <Value Type='Integer'>6</Value>
$camlQuery = "<Where><In><FieldRef Name='ID' /><Values>
                                        <Value Type='Integer'>6</Value>
                                        <Value Type='Integer'>7</Value>
                                     
                </Values></In></Where>";
$spQuery.Query = $camlQuery
$sourceItems = $list.GetItems($spQuery)
    foreach($item in $sourceItems)
    {
# To delete the documents and send to Recycle bin, use Recycle() function
    $file=$item.File.Recycle()
# To delete the documents permanently , use Delete() function
   # $file=$item.File.Delete()
   
    }

No comments:

Post a Comment