Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # replace these details (also consider using Get-Credential to enter password securely as script runs)..
- $username = "REDACTED"
- $password = "REDACTED"
- $url = "REDACTED"
- $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
- # the path here may need to change if you used e.g. C:\Lib..
- Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Runtime.dll"
- # note that you might need some other references (depending on what your script does) for example:
- Add-Type -Path "C:\Users\pchoquette\Source\Repos\PnP-Sites-Core\Assemblies\16.1\Microsoft.SharePoint.Client.Taxonomy.dll"
- # connect/authenticate to SharePoint Online and get ClientContext object..
- $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- $clientContext.Credentials = $credentials
- if (!$clientContext.ServerObjectIsNull.Value)
- {
- Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
- $web = $clientContext.Web
- $clientContext.Load($web)
- $contentTypes = $web.ContentTypes
- $clientContext.Load($contentTypes)
- $clientContext.ExecuteQuery()
- $ctCI = New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
- $ctCI.Name = "Contoso Document"
- $ctCI.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB2"
- $ctCI.Group = "Contoso Content Types"
- $myContentType = $contentTypes.Add($ctCI)
- $clientContext.Load($myContentType)
- $clientContext.ExecuteQuery()
- Write-Host $myContentType.Name
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement