Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. $SiteURL = "https://tenant.sharepoint.com/sites/site/siteAA1"
  2.  
  3. #Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
  4. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
  5. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  6.  
  7. $User = "admin@tenant.onmicrosoft.com"
  8. $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
  9. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  10.  
  11. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  12.  
  13. $Context.Credentials = $Creds
  14.  
  15. $web = $Context.Web
  16.  
  17. $Context.Load($web)
  18. $Context.ExecuteQuery()
  19.  
  20. $web.DeleteObject()
  21. $Context.ExecuteQuery()
  22. Write-Host $web.Title "Site Deleted"
  23.  
  24. #enter the site collection url
  25. $SiteURL = "https://tenant.sharepoint.com/sites/site/"
  26.  
  27.  
  28. #Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
  29. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
  30. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  31.  
  32. $User = "admin@tenant.onmicrosoft.com"
  33. $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
  34. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  35.  
  36. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  37. $Context.Credentials = $Creds
  38.  
  39. #enter server relative path of the subsite in the array
  40. #for first level subsite, it will be "siteaa1" - url would be ""https://tenant.sharepoint.com/sites/site/siteaa1"
  41. #for second level subsite, it will be "subsite/siteaa1" - url would be ""https://tenant.sharepoint.com/sites/site/subsite/siteaa1"
  42.  
  43. $array = @("siteaaa1", "siteaaa2", "siteaaa3")
  44. for ($i=0; $i -lt $array.length; $i++)
  45. {
  46.  
  47. $web = $Context.Site.OpenWeb($array[$i]);
  48.  
  49. $Context.Load($web)
  50. $Context.ExecuteQuery()
  51.  
  52. $web.DeleteObject()
  53. $Context.ExecuteQuery()
  54. Write-Host $web.Title "Site Deleted"
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement