Upload Published Files using Add-PnPFile

Brass Contributor

Hi all,


I have to upload a file and next command works fine:

 

Add-PnPFile -Path $file -Folder "/Pages" -Web $subweb -Values @{Title=$subweb.Title}


After upload the file, I get information about the file state. The file is checked out for me.
I try to use next command to publish it (using -Publish flag), but I get a message telling that the file is checked out and then it can't be published

 

Add-PnPFile -Path $file -Folder "/Pages" -Web $subweb -Values @{Title=$subweb.Title} -Publish

I dont see any flag related with CheckIn File action ¿How I can to upload a file with state Published?

 

Thank you!

5 Replies

Have you tried Set-PnPFileCheckIn?

 

 

 

 

Hi Pieter,

 

using:
 

Set-PnPFileCheckedIn  -Web $subweb -Url "/Pages/myPage.aspx" -CheckinType MajorCheckin -Comment "Version1.0"

 

 

I get the error:

Set-PnPFileCheckedIn : Value does not fall within the expected range.

 

Hi @María José Pedreira,

 

I'm quite sure that the Url expects a server relative Url

 

-Url /sites/site/subweb/Pages/default.aspx

 

After trying several posibilities eventually I got it with

 

 

Add-PnPPublishingPage -PageName 'MyCustomName' 
-Web $subweb
-Title $subweb.Title
-PageTemplateName 'MyCustomLayout'
-Publish

 

Try the "-Checkout" property. For example:

Add-PnPFile -Path ".\dummyPage.aspx" -Folder "Pages" -Checkout:$true -Publish:$true -PublishComment "PnP provisioned page"