Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $SiteURL = "https://tenant.sharepoint.com/sites/site/siteAA1"
- #Add references to SharePoint client assemblies and authenticate to Office 365 site β required for CSOM
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- $User = "admin@tenant.onmicrosoft.com"
- $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Context.Credentials = $Creds
- $web = $Context.Web
- $Context.Load($web)
- $Context.ExecuteQuery()
- $web.DeleteObject()
- $Context.ExecuteQuery()
- Write-Host $web.Title "Site Deleted"
- #enter the site collection url
- $SiteURL = "https://tenant.sharepoint.com/sites/site/"
- #Add references to SharePoint client assemblies and authenticate to Office 365 site β required for CSOM
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- $User = "admin@tenant.onmicrosoft.com"
- $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Context.Credentials = $Creds
- #enter server relative path of the subsite in the array
- #for first level subsite, it will be "siteaa1" - url would be ""https://tenant.sharepoint.com/sites/site/siteaa1"
- #for second level subsite, it will be "subsite/siteaa1" - url would be ""https://tenant.sharepoint.com/sites/site/subsite/siteaa1"
- $array = @("siteaaa1", "siteaaa2", "siteaaa3")
- for ($i=0; $i -lt $array.length; $i++)
- {
- $web = $Context.Site.OpenWeb($array[$i]);
- $Context.Load($web)
- $Context.ExecuteQuery()
- $web.DeleteObject()
- $Context.ExecuteQuery()
- Write-Host $web.Title "Site Deleted"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement