diff --git a/Content Types/Create/Create content type and add directly to SPO list/CreateContentTypeToList.ps1 b/Content Types/Create/Create content type and add directly to SPO list/CreateContentTypeToList.ps1 index 27866a6b..7ee7a51b 100644 --- a/Content Types/Create/Create content type and add directly to SPO list/CreateContentTypeToList.ps1 +++ b/Content Types/Create/Create content type and add directly to SPO list/CreateContentTypeToList.ps1 @@ -1,49 +1,45 @@ -function New-SPOContentType -{ +function New-SPOContentType{ param( - [Parameter(Mandatory=$true,Position=1)] - [string]$Username, - [Parameter(Mandatory=$true,Position=2)] - $AdminPassword, + [Parameter(Mandatory=$true,Position=1)] + [string]$Username, + [Parameter(Mandatory=$true,Position=2)] + $AdminPassword, [Parameter(Mandatory=$true,Position=3)] - [string]$Url, - [Parameter(Mandatory=$true,Position=4)] - [string]$Description, - [Parameter(Mandatory=$true,Position=5)] - [string]$Name, - [Parameter(Mandatory=$true,Position=6)] - [string]$Group, - [Parameter(Mandatory=$true,Position=7)] - [string]$ParentContentTypeID, - [Parameter(Mandatory=$true,Position=8)] - [string]$ListID - ) + [string]$Url, + [Parameter(Mandatory=$true,Position=4)] + [string]$Description, + [Parameter(Mandatory=$true,Position=5)] + [string]$Name, + [Parameter(Mandatory=$true,Position=6)] + [string]$Group, + [Parameter(Mandatory=$true,Position=7)] + [string]$ParentContentTypeID, + [Parameter(Mandatory=$true,Position=8)] + [string]$ListID + ) - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() + $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 - $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.Lists.GetByID($ListID).ContentTypes.Add($lci) + $ctx.Load($contentType) - $ContentType = $ctx.Web.Lists.GetByID($ListID).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() - } - + try{ + $ctx.ExecuteQuery() + Write-Host "Content Type " $Name " has been added to " $Url + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } }