diff --git a/Content Types/Create/Create and add content type to a content type hub/CreateContentTypeToCTH.ps1 b/Content Types/Create/Create and add content type to a content type hub/CreateContentTypeToCTH.ps1 index 5a482a9c..b46b0d2b 100644 --- a/Content Types/Create/Create and add content type to a content type hub/CreateContentTypeToCTH.ps1 +++ b/Content Types/Create/Create and add content type to a content type hub/CreateContentTypeToCTH.ps1 @@ -1,52 +1,43 @@ -function New-SPOContentType -{ -param( -[Parameter(Mandatory=$true,Position=1)] +function New-SPOContentType{ + param( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, -[Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$Description, -[Parameter(Mandatory=$true,Position=5)] + [Parameter(Mandatory=$true,Position=5)] [string]$Name, -[Parameter(Mandatory=$true,Position=6)] + [Parameter(Mandatory=$true,Position=6)] [string]$Group, -[Parameter(Mandatory=$true,Position=7)] + [Parameter(Mandatory=$true,Position=7)] [string]$ParentContentTypeID - - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - - $ctx.ExecuteQuery() - - - - $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation - $lci.Description=$Description - $lci.Name=$Name - #$lci.ID="0x0108009e862727eed04408b2599b25356e7914" - $lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID) - $lci.Group=$Group - - $ContentType = $ctx.Web.ContentTypes.Add($lci) - $ctx.Load($contentType) - try - { - - $ctx.ExecuteQuery() - Write-Host "Content Type " $Name " has been added to " $Url - } - catch [Net.WebException] - { - Write-Host $_.Exception.ToString() - } - - - + ) + + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + $ctx.ExecuteQuery() + + $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation + $lci.Description=$Description + $lci.Name=$Name + #$lci.ID="0x0108009e862727eed04408b2599b25356e7914" + $lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID) + $lci.Group=$Group + + $ContentType = $ctx.Web.ContentTypes.Add($lci) + $ctx.Load($contentType) + + try{ + $ctx.ExecuteQuery() + Write-Host "Content Type " $Name " has been added to " $Url + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } } @@ -65,4 +56,4 @@ $ParentContentTypeID="0x01" $Group="List Content Types" -New-SPOContentType -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -Description $Description -Name $Name -Group $Group -ParentContentTypeID $ParentContentTypeID \ No newline at end of file +New-SPOContentType -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -Description $Description -Name $Name -Group $Group -ParentContentTypeID $ParentContentTypeID