Add-PnPFile

Tip

We encourage you to make improvements to this documentation. Please navigate to https://github.com/pnp/powershell/blob/dev/documentation/Add-PnPFile.md to change this file.

Uploads a file to Web

Syntax

Add-PnPFile
   -Path <String>
   -Folder <FolderPipeBind>
   [-NewFileName <String>]
   [-Checkout]
   [-CheckInComment <String>]
   [-Approve]
   [-ApproveComment <String>]
   [-Publish]
   [-PublishComment <String>]
   [-UseWebDav]
   [-Values <Hashtable>]
   [-ContentType <ContentTypePipeBind>]
   [-Connection <PnPConnection>]
   [<CommonParameters>]
Add-PnPFile
   -Folder <FolderPipeBind>
   -FileName <String>
   -Stream <Stream>
   [-Checkout]
   [-CheckInComment <String>]
   [-Approve]
   [-ApproveComment <String>]
   [-Publish]
   [-PublishComment <String>]
   [-UseWebDav]
   [-Values <Hashtable>]
   [-ContentType <ContentTypePipeBind>]
   [-Connection <PnPConnection>]
   [<CommonParameters>]

Examples

EXAMPLE 1

Add-PnPFile -Path c:\temp\company.master -Folder "_catalogs/masterpage"

This will upload the file company.master to the masterpage catalog

EXAMPLE 2

Add-PnPFile -Path .\displaytemplate.html -Folder "_catalogs/masterpage/display templates/test"

This will upload the file displaytemplate.html to the test folder in the display templates folder. If the test folder does not exist it will create it.

EXAMPLE 3

Add-PnPFile -Path .\sample.doc -Folder "Shared Documents" -Values @{Modified="1/1/2016"}

This will upload the file sample.doc to the Shared Documents folder. After uploading it will set the Modified date to 1/1/2016.

EXAMPLE 4

Add-PnPFile -FileName sample.doc -Folder "Shared Documents" -Stream $fileStream -Values @{Modified="1/1/2016"}

This will add a file sample.doc with the contents of the stream into the Shared Documents folder. After adding it will set the Modified date to 1/1/2016.

EXAMPLE 5

Add-PnPFile -Path sample.doc -Folder "Shared Documents" -ContentType "Document" -Values @{Modified="1/1/2016"}

This will add a file sample.doc to the Shared Documents folder, with a ContentType of 'Documents'. After adding it will set the Modified date to 1/1/2016.

EXAMPLE 6

Add-PnPFile -Path sample.docx -Folder "Documents" -Values @{Modified="1/1/2016"; Created="1/1/2017"; Editor=23}

This will add a file sample.docx to the Documents folder and will set the Modified date to 1/1/2016, Created date to 1/1/2017 and the Modified By field to the user with ID 23. To find out about the proper user ID to relate to a specific user, use Get-PnPUser.

EXAMPLE 7

Add-PnPFile -Path sample.docx -Folder "Documents" -NewFileName "differentname.docx"

This will upload a local file sample.docx to the Documents folder giving it the filename differentname.docx on SharePoint

Parameters

-Approve

Will auto approve the uploaded file

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ApproveComment

The comment added to the approval

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-CheckInComment

The comment added to the checkin

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Checkout

If versioning is enabled, this will check out the file first if it exists, upload the file, then check it in again

Type:SwitchParameter
Position:Named
Default value:None
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:PnPConnection
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ContentType

Use to assign a ContentType to the file

Type:ContentTypePipeBind
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-FileName

Name for file

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Folder

The destination folder in the site

Type:FolderPipeBind
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-NewFileName

Filename to give the file on SharePoint

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Path

The local file path

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Publish

Will auto publish the file

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-PublishComment

The comment added to the publish action

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Stream

Stream with the file contents

Type:Stream
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-UseWebDav
Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Values

Use the internal names of the fields when specifying field names.

Single line of text: -Values @{"Title" = "Title New"}

Multiple lines of text: -Values @{"MultiText" = "New text\n\nMore text"}

Rich text: -Values @{"MultiText" = "<strong>New</strong> text"}

Choice: -Values @{"Choice" = "Value 1"}

Number: -Values @{"Number" = "10"}

Currency: -Values @{"Number" = "10"}

Currency: -Values @{"Currency" = "10"}

Date and Time: -Values @{"DateAndTime" = "03/10/2015 14:16"}

Lookup (id of lookup value): -Values @{"Lookup" = "2"}

Multi value lookup (id of lookup values as array 1): -Values @{"MultiLookupField" = "1","2"}

Multi value lookup (id of lookup values as array 2): -Values @{"MultiLookupField" = 1,2}

Multi value lookup (id of lookup values as string): -Values @{"MultiLookupField" = "1,2"}

Yes/No: -Values @{"YesNo" = $false}

Person/Group (id of user/group in Site User Info List or email of the user, separate multiple values with a comma): -Values @{"Person" = "user1@domain.com","21"}

Managed Metadata (single value with path to term): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE"}

Managed Metadata (single value with id of term): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818"} with Id of term

Managed Metadata (multiple values with paths to terms): -Values @{"MetadataField" = "CORPORATE|DEPARTMENTS|FINANCE","CORPORATE|DEPARTMENTS|HR"}

Managed Metadata (multiple values with ids of terms): -Values @{"MetadataField" = "fe40a95b-2144-4fa2-b82a-0b3d0299d818","52d88107-c2a8-4bf0-adfa-04bc2305b593"}

Hyperlink or Picture: -Values @{"Hyperlink" = "https://github.com/OfficeDev/, OfficePnp"}

Type:Hashtable
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False