1) Create CSV files based on your requirement and place desired location
$csvLocation = ".\PS_SiteCollectionsToCreate.csv"
$template = “STS#0”
$siteUrl = “https://Yourcorp.sharepoint.com/sites/SPOTest2/”
$username = “kamal@abc.com”#yourpassword
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”
$password = Read-Host -Prompt “Enter password” -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext ($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$csv = Import-Csv $csvLocation
ForEach ($site in $csv)
{
$site = $($site.collumname)
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = $site
$webCreationInformation.Title = $site
$webCreationInformation.WebTemplate = $template
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
#$newWeb.ResetRoleInheritance()
$ctx.Load($newWeb)
$ctx.ExecuteQuery()
Write-Host “Site created:” $newWeb.Title ” at: ” $siteUrl “/” $newWeb.Url
}
$csvLocation = ".\PS_SiteCollectionsToCreate.csv"
$template = “STS#0”
$siteUrl = “https://Yourcorp.sharepoint.com/sites/SPOTest2/”
$username = “kamal@abc.com”#yourpassword
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”
$password = Read-Host -Prompt “Enter password” -AsSecureString
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext ($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Credentials = $credentials
$csv = Import-Csv $csvLocation
ForEach ($site in $csv)
{
$site = $($site.collumname)
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = $site
$webCreationInformation.Title = $site
$webCreationInformation.WebTemplate = $template
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
#$newWeb.ResetRoleInheritance()
$ctx.Load($newWeb)
$ctx.ExecuteQuery()
Write-Host “Site created:” $newWeb.Title ” at: ” $siteUrl “/” $newWeb.Url
}
Comments
Post a Comment