TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sreeram MUNIRAJA
NA
87
22k
Delete SharePoint Sub sites
Jun 5 2018 5:11 AM
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
Reply
Answers (
5
)
SharePoint Server Publishing Infrastructure
Sharepoint Online: DatefieldError