Add-Type -Path "\Software\SharePoint 2013 Client Browser v1.7\Microsoft.SharePoint.Client.dll"
Add-Type -Path "\Software\SharePoint 2013 Client Browser v1.7\Microsoft.SharePoint.Client.Runtime.dll"
$siteUrl = “https://yourcorp.sharepoint.com/sites/SPOTest2/”
$username = "abd@anc.com"
$password = Read-Host -Prompt "Password" -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$csvLocation = ".\PS_SiteCollectionsToCreate.csv"
$ctx.Credentials = $credentials
$csv = Import-Csv $csvLocation
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host " Getting Data from CSV files" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
ForEach ($site in $csv)
{
$site = $($site.SiteCRelativeUrl)
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Creating a new Site Collection in SharePoint Online" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$webCreationInformation.Url = $site
$webCreationInformation.Title = $site
$webCreationInformation.WebTemplate = $template
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
$newWeb.ResetRoleInheritance()
$ctx.Load($newWeb)
$ctx.ExecuteQuery()
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Site Collection-Subsite" $newWeb.Title "succesfully created!!!"
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
}
Comments
Post a Comment