Add-PnPField

Add a field

Syntax

Add-PnPField
   [-AddToDefaultView [<SwitchParameter>]]
               [-Required [<SwitchParameter>]]
               [-Group <String>]
               [-Web <WebPipeBind>]
               [-Connection <SPOnlineConnection>]
Add-PnPField
   -List <ListPipeBind>
               -Field <FieldPipeBind>
               [-Web <WebPipeBind>]
               [-Connection <SPOnlineConnection>]
Add-PnPField
   -DisplayName <String>
               -InternalName <String>
               -Type <FieldType>
               [-List <ListPipeBind>]
               [-Id <GuidPipeBind>]
               [-AddToDefaultView [<SwitchParameter>]]
               [-Required [<SwitchParameter>]]
               [-Group <String>]
               [-ClientSideComponentId <GuidPipeBind>]
               [-ClientSideComponentProperties <String>]
               [-Choices <String[]>]
               [-Formula <String>]
               [-Web <WebPipeBind>]
               [-Connection <SPOnlineConnection>]
Add-PnPField
   -DisplayName <String>
               -InternalName <String>
               -Type <FieldType>
               [-Id <GuidPipeBind>]
               [-ClientSideComponentId <GuidPipeBind>]
               [-ClientSideComponentProperties <String>]
               [-Choices <String[]>]
               [-Formula <String>]
               [-Web <WebPipeBind>]
               [-Connection <SPOnlineConnection>]

Description

Adds a field to a list or as a site column

Examples

------------------EXAMPLE 1------------------

Add-PnPField -Type Calculated -InternalName "C1" -DisplayName "C1" -Formula ="[Title]"

Adds a new calculated site column with the formula specified

------------------EXAMPLE 2------------------

Add-PnPField -List "Demo list" -DisplayName "Location" -InternalName "SPSLocation" -Type Choice -Group "Demo Group" -AddToDefaultView -Choices "Stockholm","Helsinki","Oslo"

This will add a field of type Choice to the list "Demo List".

------------------EXAMPLE 3------------------

PS:>Add-PnPField -List "Demo list" -DisplayName "Speakers" -InternalName "SPSSpeakers" -Type MultiChoice -Group "Demo Group" -AddToDefaultView -Choices "Obiwan Kenobi","Darth Vader", "Anakin Skywalker"

This will add a field of type Multiple Choice to the list "Demo List". (you can pick several choices for the same item)

Parameters

-AddToDefaultView

Switch Parameter if this field must be added to the default view

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Choices

Specify choices, only valid if the field type is Choice

Type:String[]
Position:0
Accept pipeline input:False
Accept wildcard characters:False
-ClientSideComponentId

The Client Side Component Id to set to the field

Only applicable to: SharePoint Online

Type:GuidPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-ClientSideComponentProperties

The Client Side Component Properties to set to the field

Only applicable to: SharePoint Online

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Connection

Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

Type:SPOnlineConnection
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-DisplayName

The display name of the field

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Field

The name of the field, its ID or an actual field object that needs to be added

Type:FieldPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Formula

Specify the formula. Only available if the field type is Calculated

Type:String
Position:0
Accept pipeline input:False
Accept wildcard characters:False
-Group

The group name to where this field belongs to

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Id

The ID of the field, must be unique

Type:GuidPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-InternalName

The internal name of the field

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-List

The name of the list, its ID or an actual list object where this field needs to be added

Type:ListPipeBind
Position:Named
Accept pipeline input:True
Accept wildcard characters:False
-Required

Switch Parameter if the field is a required field

Type:SwitchParameter
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Type

The type of the field like Choice, Note, MultiChoice. For a complete list of field types visit https://docs.microsoft.com/dotnet/api/microsoft.sharepoint.client.fieldtype

Type:FieldType
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Web

This parameter allows you to optionally apply the cmdlet action to a subweb within the current web. In most situations this parameter is not required and you can connect to the subweb using Connect-PnPOnline instead. Specify the GUID, server relative url (i.e. /sites/team1) or web instance of the web to apply the command to. Omit this parameter to use the current web.

Type:WebPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False

Outputs

Microsoft.SharePoint.Client.Field