Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. # replace these details (also consider using Get-Credential to enter password securely as script runs)..
  2. $username = "REDACTED"
  3. $password = "REDACTED"
  4. $url = "REDACTED"
  5.  
  6. $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
  7.  
  8. # the path here may need to change if you used e.g. C:\Lib..
  9. Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.dll"
  10. Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Runtime.dll"
  11. # note that you might need some other references (depending on what your script does) for example:
  12. Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Taxonomy.dll"
  13.  
  14. # connect/authenticate to SharePoint Online and get ClientContext object..
  15. $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
  16. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  17. $clientContext.Credentials = $credentials
  18.  
  19. if (!$clientContext.ServerObjectIsNull.Value)
  20. {
  21. Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
  22.  
  23. $web = $clientContext.Web
  24. $clientContext.Load($web)
  25. $contentTypes = $web.ContentTypes
  26. $clientContext.Load($contentTypes)
  27. $clientContext.ExecuteQuery()
  28.  
  29. $ctCI = New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
  30. $ctCI.Name = "Contoso Document"
  31. $ctCI.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB2"
  32. $ctCI.Group = "Contoso Content Types"
  33. $myContentType = $contentTypes.Add($ctCI)
  34. $clientContext.Load($myContentType)
  35. $clientContext.ExecuteQuery()
  36.  
  37. Write-Host $myContentType.Name
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement