Hi All,
I have power shell code to delete SharePoint Sub sites. But this code delete the site perminantly. But i want to go site into Recycle Bin once delete the site.
Can you please change below my scrript?
#Variables for Processingn
$SiteUrl = "https://tenant.sharepoint"
$UserName="test @gmail.com"
$Password ="********"
try{
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$context.Credentials = $credentials
#get the subsite
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
#Delete subsite
$web.DeleteObject()
$context.ExecuteQuery()
Write-Host "SubSite Deleted:" $web.Title -foregroundcolor Green
}
catch{
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Best regards

Chanakya JayabalanRank #1,183 · 1.5K reputationPosted Jun 11, 2018, 6:49 AM EDT
Nanddeep NachanRank #38 · 35.2K reputationPosted Jun 6, 2018, 5:22 AM EDT
Sreeram MUNIRAJA101 reputationPosted Jun 6, 2018, 9:44 PM EDT
Manpreet SinghRank #15 · 50.7K reputationPosted Jul 30, 2018, 11:22 AM EDT
Nanddeep NachanRank #38 · 35.2K reputationPosted Jul 30, 2018, 9:40 PM EDT