Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Create-SPOContentType($ctx, $Name, $Description, $group, $templateExt, $isParentId, $id){
- $baseTemplateUrl = "/sites/contenttypehub/FormServerTemplates/template"
- write-host "Creating $($Name) content type ... " -NoNewline
- $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
- If($isParentId){
- $lci.ParentContentType = $ctx.Web.ContentTypes.GetById($id)
- } else {
- $lci.ID = $Id
- }
- $lci.Name = $Name
- $lci.Description = $Description
- $lci.Group = $group
- $contentType = $ctx.Web.ContentTypes.Add($lci)
- $contentType.DocumentTemplate = ($baseTemplateUrl + $templateExt)
- $contentType.Update($true)
- try{
- $ctx.executeQuery()
- write-host "$($Name) created." -ForegroundColor Green
- }
- catch{
- write-host
- write-host "Error while creating $($Name)" -foregroundcolor red
- write-host "Error Message $($_.Exception.Message) $($_.Exception.Message)" -foregroundcolor red
- }
- }
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
- $siteUrl = Read-Host -Prompt "Provide the URL"
- $adminUsername = Read-Host -Prompt ("Provide user for {0}" -f $siteUrl)
- $secureAdminPassword = Read-Host -Prompt ("Provide password for {0}" -f $adminUsername) -AsSecureString
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUsername, $secureAdminPassword)
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $ctx.Credentials = $credentials
- Create-SPOContentType $ctx "Word Document PSCT" "" "PowerSheel Content Types" ".docx" $false "0x0101000728167cd9c94899925ba69c4af6743e"
- Create-SPOContentType $ctx "Excel Document PSCT" "" "PowerSheel Content Types" ".xlsx" $true "0x0101"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement