Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. function Create-SPOContentType($ctx, $Name, $Description, $group, $templateExt, $isParentId, $id){
  2. $baseTemplateUrl = "/sites/contenttypehub/FormServerTemplates/template"
  3. write-host "Creating $($Name) content type ... " -NoNewline
  4.  
  5. $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
  6. If($isParentId){
  7. $lci.ParentContentType = $ctx.Web.ContentTypes.GetById($id)
  8. } else {
  9. $lci.ID = $Id
  10. }
  11.  
  12. $lci.Name = $Name
  13. $lci.Description = $Description
  14. $lci.Group = $group
  15.  
  16. $contentType = $ctx.Web.ContentTypes.Add($lci)
  17.  
  18. $contentType.DocumentTemplate = ($baseTemplateUrl + $templateExt)
  19. $contentType.Update($true)
  20.  
  21. try{
  22. $ctx.executeQuery()
  23. write-host "$($Name) created." -ForegroundColor Green
  24. }
  25. catch{
  26. write-host
  27. write-host "Error while creating $($Name)" -foregroundcolor red
  28. write-host "Error Message $($_.Exception.Message) $($_.Exception.Message)" -foregroundcolor red
  29. }
  30. }
  31.  
  32. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
  33. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  34.  
  35. $siteUrl = Read-Host -Prompt "Provide the URL"
  36. $adminUsername = Read-Host -Prompt ("Provide user for {0}" -f $siteUrl)
  37. $secureAdminPassword = Read-Host -Prompt ("Provide password for {0}" -f $adminUsername) -AsSecureString
  38.  
  39. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($adminUsername, $secureAdminPassword)
  40. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  41. $ctx.Credentials = $credentials
  42.  
  43. Create-SPOContentType $ctx "Word Document PSCT" "" "PowerSheel Content Types" ".docx" $false "0x0101000728167cd9c94899925ba69c4af6743e"
  44. Create-SPOContentType $ctx "Excel Document PSCT" "" "PowerSheel Content Types" ".xlsx" $true "0x0101"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement