0

I have created a taxonomy type site column using PowerShell Script. I need to enable "Allow multiple values" property using script.

I have searched a lot. In some solutions it says it's possible while adding the column to the list. But I need that property set while creating the site column itself.

Below is the code which I used to create the site column.

 $fieldAsXML = "<Field Type='$($column.FieldType)' 
 DisplayName='$($column.DisplayName)' 
 Name='$($column.name)'     
 Group='$($column.group)'
 Required='$($column.required)'/>"

 #see tips below for info about fieldOptions
 $fieldOption = [Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint
 $field = $fields.AddFieldAsXML($fieldAsXML, $true, $fieldOption)
 $context.load($field)

Any help is appreciated.

Thanks.

Update:

For Taxonomy I used, Lee_MSFT's answer.

For Lookup I used, the below method:

$fieldAsXML = "<Field Type='LookupMulti' 
DisplayName='$($column.DisplayName)' 
Name='$($column.name)'     
Group='$($column.group)'
Mult='TRUE'
Required='$($column.required)' 
List='$($column.List)'
ShowField='$($column.ShowField)'/>"

For Taxonomy, we can also use Field Type='TaxonomyFieldTypeMulti' and Mult='TRUE' properties.

Aswathy Santhosh
  • 125
  • 4
  • 18
  • I believe you are looking for the `[Microsoft.SharePoint.Client.FieldLookup]::AllowMultipleValues`. I did a quick search and found this blog describing how to use it: http://www.sharepointdiary.com/2013/12/get-set-lookup-field-values-in-sharepoint-using-powershell.html. Hope that helps – Theo Jul 11 '18 at 18:31

1 Answers1

1

I would suggest you use Add-PnPTaxonomyField.

Connect-PNPOnline -Url https://domain.sharepoint.com/sites/Developer

Add-PnPTaxonomyField -List "MyDoc4" -DisplayName "Testa" -InternalName "Testa" -MultiValue -TermSetPath "Test|Global"
Lee
  • 5,305
  • 1
  • 6
  • 12
  • Hi, I refered pnp powershell microsoft articles as you have mentioned in the answer. I think it will work directly when given in command prompt. But I have trouble in incorporating it to my script. I have seen this solution. [link](https://github.com/SharePoint/PnP-PowerShell/blob/master/Samples/Audiences.Retrieve/GetWebPartsAudience.ps1). I have downloaded and installed the latest pnp release. But not able to find the dll associated with it(Import-Module b:\PnPPowerShell\V16\OfficeDevPnP.PowerShell.Commands.dll). Any idea how this can be implemented in code? – Aswathy Santhosh Jul 13 '18 at 07:56
  • I installed the module from https://github.com/sharepoint/pnp-powershell/releases and can use it globally. – Lee Jul 13 '18 at 08:46