-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateSiteCollection_PSCmdlet.ps1
53 lines (46 loc) · 2.87 KB
/
CreateSiteCollection_PSCmdlet.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
############################################################################################################################################
# Script that allows to create a new site collection in SharePoint Online
# Required Parameters:
# -> $sUserName: User Name to connect to the SharePoint Admin Center.
# -> $sMessage: Message to show in the user credentials prompt.
# -> $sSPOAdminCenterUrl: SharePoint Admin Center Url
# -> $sSiteColTitle: Site Collection Title
# -> $sSiteColUrl: Site Collection Url
# -> $sOwner: Site Collection Owner
# -> $iLocaleID: Language ID for the Site Collection
# -> $sTemplateID: SharePoint Template to create the Site Collection
# -> $iStorageQuota: Site Collection Storage Quota
############################################################################################################################################
$host.Runspace.ThreadOptions = "ReuseThread"
#Definition of the function that gets all the site collections information in a SharePoint Online tenant
function Create-SPOSiteCollection
{
param ($sUserName,$sMessage,$sSiteColTitle,$sSiteColUrl,$sOwner,$iLocaleID,$sTemplateID,$iStorageQuota)
try
{
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Creating a new Site Collection in SharePoint Online" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$msolcred = get-credential -UserName $sUserName -Message $sMessage
Connect-SPOService -Url $sSPOAdminCenterUrl -Credential $msolcred
New-SPOSite -Title $sSiteColTitle -Url $sSiteColUrl -Owner $sOwner -LocaleId $iLocaleID -Template $sTemplateID -StorageQuota $iStorageQuota
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Site Collection succesfully created!!!" -foregroundcolor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Connection to Office 365
$sUserName="<YourOffice365Account>"
$sMessage="Introduce your SPO Credentials"
$sSPOAdminCenterUrl="https://<YourDomain>-admin.sharepoint.com/"
$sSiteColTitle="SPO PowerShell Site Col"
$sSiteColUrl="https://<YourDomain>.sharepoint.com/sites/SPOPowerShellSiteC"
$sOwner="<Office365User>@<YourDomain>.onmicrosoft.com"
$iLocaleID=3082
$sTemplateID="STS#0"
$iStorageQuota=1024
Create-SPOSiteCollection -sUserName $sUserName -sMessage $sMessage -sSiteColTitle $sSiteColTitle -sSiteColUrl $sSiteColUrl -sOwner $sOwner -iLocaleID $iLocaleID -sTemplateID $sTemplateID -iStorageQuota $iStorageQuota