Get-SPOWebTemplate.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID d96e05b3-ab4c-4911-87cf-57eb65c52b54
 
.AUTHOR Chendrayan Venkatesan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS SharePoint Online
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
.SYNOPSIS
    Retrieves SharePoint Online Web Template information.
.DESCRIPTION
    Get-xSPOWebTemplate will retrieve all the Web Template details.
.EXAMPLE
    Get-xSPOWebTempalte -Url "https://contoso.sharepoint.com" -Credential "Admin@contoso.onmicrosoft.com" -Licd 1033 -DoIncludeCrossLanguage $True
.EXAMPLE
    "https://contoso.sharepoint.com" , "https://chensoffice365.sharepoint.com/sites/demo12" |
     Get-xSPOWebTemplate -Credential "Admin@contoso.onmicrosoft.com" -Lcid 1036 -DoIncludeCrossLangauge $false
.EXAMPLE
    Get-xSPOWebTempalte -Url "https://contoso.sharepoint.com" -Credential "Admin@contoso.onmicrosoft.com" -Licd 1033 -DoIncludeCrossLanguage $True | Select -Property <Tab Completes>
.NOTES
    CSOM SDK Assemblies are mandatory. To install CSOM package refer this link https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM
#>

 
 param
    (
        # SharePoint Online Url
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)]
        [uri]$Url,

        # SharePoint Online Admin Credential
        [System.Management.Automation.CredentialAttribute()]
        [Parameter(Mandatory)]
        [pscredential]
        $Credential,

        # LCID
        [Parameter(Mandatory)]
        [uint32]$Lcid,

        # To Get Other Language Information
        [Parameter(Mandatory)]
        [bool]$DoIncludeCrossLanguage
    )
#Change the location of assemblies as required
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll'
function Get-xSPOWebTemplate
{

    [CmdletBinding()]
    [OutputType([Microsoft.SharePoint.Client.WebTemplate])]
    param
    (
        # SharePoint Online Url
        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,Position=0)]
        [uri]$Url,

        # SharePoint Online Admin Credential
        [System.Management.Automation.CredentialAttribute()]
        [Parameter(Mandatory)]
        [pscredential]
        $Credential,

        # LCID
        [Parameter(Mandatory)]
        [uint32]$Lcid,

        # To Get Other Language Information
        [Parameter(Mandatory)]
        [bool]$DoIncludeCrossLanguage
    )

    process
    {
            try 
            {
                $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url);
                $SPOClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Credential.UserName,$Credential.Password)
                $oWebTemplateCollection = $SPOClientContext.Web.GetAvailableWebTemplates($Lcid , $DoIncludeCrossLanguage)
                $SPOClientContext.Load($oWebTemplateCollection)
                $SPOClientContext.ExecuteQuery()
                $SPOClientContext.Dispose()
                foreach($oWebTemplate in $oWebTemplateCollection)
                {
                    $oWebTemplate
                }

            }
            catch 
            {
                $_.Exception.Message
            }
    }
}