Table of contents
TOC
Collapse the table of content
Expand the table of content

Add-PnPFile

Bert Jansen|Last Updated: 2/20/2017
|
1 Contributor

Uploads a file to Web

Syntax

Add-PnPFile -Path <String>
            -Folder <String>
            [-Checkout [<SwitchParameter>]]
            [-CheckInComment <String>]
            [-Approve [<SwitchParameter>]]
            [-ApproveComment <String>]
            [-Publish [<SwitchParameter>]]
            [-PublishComment <String>]
            [-UseWebDav [<SwitchParameter>]]
            [-Values <Hashtable>]
            [-ContentType <ContentTypePipeBind>]
            [-Web <WebPipeBind>]
Add-PnPFile -FileName <String>
            -Stream <Stream>
            -Folder <String>
            [-Checkout [<SwitchParameter>]]
            [-CheckInComment <String>]
            [-Approve [<SwitchParameter>]]
            [-ApproveComment <String>]
            [-Publish [<SwitchParameter>]]
            [-PublishComment <String>]
            [-UseWebDav [<SwitchParameter>]]
            [-Values <Hashtable>]
            [-ContentType <ContentTypePipeBind>]
            [-Web <WebPipeBind>]

Returns

Microsoft.SharePoint.Client.File

Parameters

ParameterTypeRequiredDescription
FileNameStringTrueName for file
FolderStringTrueThe destination folder in the site
PathStringTrueThe local file path.
StreamStreamTrueStream with the file contents
ApproveSwitchParameterFalseWill auto approve the uploaded file.
ApproveCommentStringFalseThe comment added to the approval.
CheckInCommentStringFalseThe comment added to the checkin.
CheckoutSwitchParameterFalseIf versioning is enabled, this will check out the file first if it exists, upload the file, then check it in again.
ContentTypeContentTypePipeBindFalseUse to assign a ContentType to the file.
PublishSwitchParameterFalseWill auto publish the file.
PublishCommentStringFalseThe comment added to the publish action.
UseWebDavSwitchParameterFalse
ValuesHashtableFalseUse the internal names of the fields when specifying field names
WebWebPipeBindFalseThe web to apply the command to. Omit this parameter to use the current web.

Examples

Example 1

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

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

Example 2

PS:> 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

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

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

Example 4

PS:> 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

PS:> Add-PnPFile -FileName 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.

© 2017 Microsoft