SharePointOnline.ps1

<#
    .SYNOPSIS
        Creates a new SharePoint Online Site collection
    .DESCRIPTION
        Creates a new SharePoint online Site collection under Office 365. Must have a full enterprise O365 license.
    .LINK
        Nexus Innovations : http://www.nexusinno.com
    --------------------------------------------------------------------------------------
    Module 'Nexus.PSToolkit'
    by: Nexus Innovations.
    --------------------------------------------------------------------------------------
#>

function global:New-NexusSPOSite {
    Param(
        [Parameter(Mandatory=$true)]
        [PSObject]$SiteInfo,

        [switch]$Force
    )

    # Will throw an error if site already exists, just gulp it to avoid unnecessary noise during deployment phase!
    # We really just wanna know if the site is already in place.
    $site = Get-PnPTenantSite -Url $SiteCollectionUrl -ErrorAction SilentlyContinue
    if($site) {
        if($Force) {
            Write-Warning "Force parameter detected. The $($SiteInfo.Url) site collection will be deleted!"
            Remove-PnPTenantSite -Url $SiteInfo.Url -Force -SkipRecycleBin
            Write-Host "Creating site $($SiteInfo.Url)..." -NoNewline
            $site = New-PnpTenantSite -Url $SiteInfo.Url -Title $SiteInfo.Title -TimeZone $SiteInfo.TimeZone -Owner $SiteInfo.Owner -Wait
            Write-Host " success!" -ForegroundColor Green
        } else {
            Write-Warning "Site already exists, use the Force Switch parameter to recreate the site!"
        }
    } else {
        Write-Host "Creating site $($SiteInfo.Url)..." -NoNewline
        $site = New-PnpTenantSite -Url $SiteInfo.Url -Title $SiteInfo.Title -TimeZone $SiteInfo.TimeZone -Owner $SiteInfo.Owner -Wait
        Write-Host " success!" -ForegroundColor Green
    }

    return $site
}

<#
    .SYNOPSIS
        Creates a new SharePoint Online Site collection information object
    .DESCRIPTION
        Creates a new custom PSObject containing the information needed to provision a new site collection on SharePoint Online.
        The timezone is defaulted to GMT -5 East US.
    .LINK
        Nexus Innovations : http://www.nexusinno.com
    --------------------------------------------------------------------------------------
    Module 'Nexus.PSToolkit'
    by: Nexus Innovations.
    --------------------------------------------------------------------------------------
#>

function global:New-SiteInfo {
    Param (
        [Parameter(Mandatory=$true)]
        [ValidatePattern("https\:\/\/[\D\d]*\.sharepoint\.com\/sites\/[\D\d]*")]
        [string]$SiteCollectionUrl,

        [Parameter(Mandatory=$true)]
        [string]$SiteCollectionOwner,
        
        [Parameter(Mandatory=$true)]
        [string]$SiteCollectionTitle,

        [string]$TimeZone = "10" # UTCMINUS0500_EASTERN_TIME_US_AND_CANADA
    )

    $properties = @{Url = $SiteCollectionUrl; Owner = $SiteCollectionOwner; TimeZone = $TimeZone; Title = $SiteCollectionTitle}
    return New-Object PSObject -Property $properties
}

<#
    .SYNOPSIS
        Creates a new SharePoint Feature information object
    .DESCRIPTION
        Creates a new custom PSObject containing the information needed to enable a SharePoint Online feature.
        Required GUID format will be validated by the Cmdlet.
    .LINK
        Nexus Innovations : http://www.nexusinno.com
    --------------------------------------------------------------------------------------
    Module 'Nexus.PSToolkit'
    by: Nexus Innovations.
    --------------------------------------------------------------------------------------
#>

function global:New-FeatureInfo {
    Param (
        [Parameter(Mandatory=$true)]
        [ValidateScript({
            try {
                [System.Guid]::Parse($_) | Out-Null
                $true
            } catch {
                $false
            } 
        })]
        [string]$Guid,

        [ValidateSet("Site", "Web")]
        [Parameter(Mandatory=$true)]
        [string]$Scope,

        [string]$Description = [string]::Empty
    )

    $properties = @{Guid = $Guid; Description = $Description; Scope = $Scope}
    return New-Object PSObject -Property $properties
}

<#
    .SYNOPSIS
        Enables a collection of features (OOTB or custom made) on a SharePoint online Site Collection.
    .DESCRIPTION
        Enables a collection of features (OOTB or custom made) on a SharePoint online Site Collection.
        The collection uses PSObject that can be created via the New-FeatureInfo Cmdlet supplied with this toolkit.
    .LINK
        SharePoint OOTB features GUID : http://www.spsdemo.com/lists/features/all%20sharepoint%20features.aspx
        Nexus Innovations : http://www.nexusinno.com
    --------------------------------------------------------------------------------------
    Module 'Nexus.PSToolkit'
    by: Nexus Innovations.
    --------------------------------------------------------------------------------------
#>

function global:Enable-NexusFeatures {
    Param (
        [Parameter(Mandatory=$true)]
        [array]$Features
    )

    $features | ForEach-Object {
        try {            
            Write-Host "Enabling $($_.Scope) Feature : $($_.Description) ..." -NoNewline 
            Enable-PnPFeature -Identity $_.Guid -Scope $_.Scope -Force
            Write-Host " done!" -ForegroundColor Green
        } catch {
            Write-Host " failed!" -ForegroundColor Red
            Write-Host $_.Exception.Message
        }
    }
}