Upload Published Files using Add-PnPFile

%3CLINGO-SUB%20id%3D%22lingo-sub-65002%22%20slang%3D%22en-US%22%3EUpload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65002%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20have%20to%20upload%20a%20file%20and%20next%20command%20works%20fine%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-PnPFile%20-Path%20%24file%20-Folder%20%22%2FPages%22%20-Web%20%24subweb%20-Values%20%40%7BTitle%3D%24subweb.Title%7D%3C%2FPRE%3E%3CP%3E%3CBR%20%2F%3EAfter%20upload%20the%20file%2C%20I%20get%20information%20about%20the%20file%20state.%20The%20file%20is%20checked%20out%20for%20me.%3CBR%20%2F%3EI%20try%20to%20use%20next%20command%20to%20publish%20it%20(using%20-Publish%20flag)%2C%20but%20I%20get%20a%20message%20telling%20that%20the%20file%20is%20checked%20out%20and%20then%20it%20can't%20be%20published%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-PnPFile%20-Path%20%24file%20-Folder%20%22%2FPages%22%20-Web%20%24subweb%20-Values%20%40%7BTitle%3D%24subweb.Title%7D%20%3CSTRONG%3E-Publish%3C%2FSTRONG%3E%3C%2FPRE%3E%3CP%3EI%20dont%20see%20any%20flag%20related%20with%20CheckIn%26nbsp%3BFile%20action%20%C2%BFHow%20I%20can%20to%20upload%20a%20file%20with%20state%20Published%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-213724%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-213724%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20the%20%22-Checkout%22%20property.%20For%20example%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3EAdd-PnPFile%3C%2FFONT%3E%3CFONT%20color%3D%22%23000080%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E-Path%3C%2FFONT%3E%3CFONT%20color%3D%22%238b0000%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E%22.%5CdummyPage.aspx%22%3C%2FFONT%3E%3CFONT%20color%3D%22%23000080%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E-Folder%3C%2FFONT%3E%3CFONT%20color%3D%22%238b0000%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E%22Pages%22%3C%2FFONT%3E%3CFONT%20color%3D%22%23000080%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E-Checkout%3A%3C%2FFONT%3E%3CFONT%20color%3D%22%23ff4500%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E%24true%3C%2FFONT%3E%3CFONT%20color%3D%22%23000080%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E-Publish%3A%3C%2FFONT%3E%3CFONT%20color%3D%22%23ff4500%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E%24true%3C%2FFONT%3E%3CFONT%20color%3D%22%23000080%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E-PublishComment%3C%2FFONT%3E%3CFONT%20color%3D%22%238b0000%22%20face%3D%22Lucida%20Console%22%20size%3D%221%22%3E%22PnP%20provisioned%20page%22%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65135%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65135%22%20slang%3D%22en-US%22%3E%3CP%3EAfter%20trying%20several%20posibilities%20eventually%20I%20got%20it%20with%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-PnPPublishingPage%20-PageName%20'MyCustomName'%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-Web%20%24subweb%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-Title%20%24subweb.Title%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-PageTemplateName%20'MyCustomLayout'%20%3CBR%20%2F%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-Publish%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65061%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65061%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F47968%22%20target%3D%22_blank%22%3E%40Mar%C3%ADa%20Jos%C3%A9%20Pedreira%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20quite%20sure%20that%20the%20Url%20expects%20a%20server%20relative%20Url%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E-Url%20%2Fsites%2Fsite%2Fsubweb%2FPages%2Fdefault.aspx%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65048%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65048%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Pieter%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eusing%3A%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESet-PnPFileCheckedIn%20%20-Web%20%24subweb%20-Url%20%22%2FPages%2FmyPage.aspx%22%20-CheckinType%20MajorCheckin%20-Comment%20%22Version1.0%22%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20the%20error%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3ESet-PnPFileCheckedIn%20%3A%20Value%20does%20not%20fall%20within%20the%20expected%20range.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65028%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Published%20Files%20using%20Add-PnPFile%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65028%22%20slang%3D%22en-US%22%3E%3CP%3EHave%20you%20tried%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Fpnp_powershell%2Fsetpnpfilecheckedin%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ESet-PnPFileCheckIn%3C%2FA%3E%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted
Highlighted

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.

 

Highlighted

Hi @María José Pedreira,

 

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

 

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

 

Highlighted

After trying several posibilities eventually I got it with

 

 

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

 

Highlighted

Try the "-Checkout" property. For example:

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