SOLVED

Upload Pages using Powershell / PnP

%3CLINGO-SUB%20id%3D%22lingo-sub-64347%22%20slang%3D%22en-US%22%3EUpload%20Pages%20using%20Powershell%20%2F%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64347%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20to%20upload%20the%20same%20Page%20into%20the%20Pages%20library%20in%20several%20webs.%20In%20my%20example%2C%20I'm%20located%20in%20my%20root%20path%20(http%3A%2F%2Fmyhost%2FPages)%20and%20the%20first%203%20lines%20work%20ok.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20an%20error%20in%20my%20line%204%2C%20when%20I%20try%20to%20upload%20the%20page%20into%20a%20subsite%20http%3A%2F%2Fmyhost%2FFirstWeb%2FPages%2F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E1%20%24file%20%3D%20((%24PSScriptRoot)%20%2B%20%22%5C..%5CPages%5CPageToUpload.aspx%22)%3CBR%20%2F%3E2%20Add-PnPFile%20-Path%20%24file%20-Folder%20%22%2FPages%22%20%3CBR%20%2F%3E3%20Set-PnPFileCheckedIn%20-Url%20%22%2FPages%2FPageToUpload.aspx%22%20-CheckinType%20MajorCheckin%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E4%20Add-PnPFile%20-Path%20%24file%20-Folder%20%22%2FPages%22%20-Web%20%22%2FFirstWeb%22%3CBR%20%2F%3E5%20Set-PnPFileCheckedIn%20-Web%20%22%2FFirstWeb%22%20-Url%20%22%2FPages%2FPageToUpload.aspx%22%20-CheckinType%20MajorCheckin%3CBR%20%2F%3E%0A%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20do%20I%20have%20to%20do%20to%20change%20into%20the%20correct%20subsite%20FirstWeb%20to%20upload%20my%20page%20again%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20in%20advanced!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-64353%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Pages%20using%20Powershell%20%2F%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64353%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%2F2387%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%2C%20first%20of%20all%2C%20thank%20you%20for%20your%20fast%20response...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20tried%20%26nbsp%3Bthis%20code%20instead%204-5%20lines%20and%20Pages%20upload%20ok.%20Thank%20you!!%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%3Eforeach%20(%24subweb%20in%20Get-PnPSubWebs%20)%20%7B%0A%20Add-PnPFile%20-Path%20%24file%20-Folder%20%22%2FPages%22%20%20-Web%20%24subweb%3CBR%20%2F%3E%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-64349%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Pages%20using%20Powershell%20%2F%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64349%22%20slang%3D%22en-US%22%3E%3CP%3EI%20think%20it%20it%20your%20firstweb...%20maybe%26nbsp%3Byou%20fill%20in%20the%20whole%20path.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-64348%22%20slang%3D%22en-US%22%3ERe%3A%20Upload%20Pages%20using%20Powershell%20%2F%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-64348%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%3EWhat%20is%20the%20error%20that%20you%20get%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20you%20tried%20using%20a%20web%20object%20rather%20than%20a%20web%20url%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Add-PnPFile%20-Path%20%24filePath%20-Web%20%24Web%20-Folder%20%24folder%3C%2FPRE%3E%3CP%3EAlso%20have%20you%20tried%20with%20the%20%2F%20in%20the%20web%20url%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20general%20I%20use%20Get-PnPWeb%20and%20Get-PnPSubWebs%20to%20get%20my%20web%20object%20before%20calling%20Add-%40PnPFile%20and%20that%20seems%20to%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I need to upload the same Page into the Pages library in several webs. In my example, I'm located in my root path (http://myhost/Pages) and the first 3 lines work ok.

 

I get an error in my line 4, when I try to upload the page into a subsite http://myhost/FirstWeb/Pages/

 

 

1 $file = (($PSScriptRoot) + "\..\Pages\PageToUpload.aspx")
2 Add-PnPFile -Path $file -Folder "/Pages"
3 Set-PnPFileCheckedIn -Url "/Pages/PageToUpload.aspx" -CheckinType MajorCheckin


4 Add-PnPFile -Path $file -Folder "/Pages" -Web "/FirstWeb"
5 Set-PnPFileCheckedIn -Web "/FirstWeb" -Url "/Pages/PageToUpload.aspx" -CheckinType MajorCheckin

 

What do I have to do to change into the correct subsite FirstWeb to upload my page again?

 

 

Thank you in advanced!

3 Replies
best response confirmed by María José Pedreira (Contributor)
Solution

Hi @María José Pedreira,

 

What is the error that you get?

 

Have you tried using a web object rather than a web url?

 

      Add-PnPFile -Path $filePath -Web $Web -Folder $folder

Also have you tried with the / in the web url?

 

In general I use Get-PnPWeb and Get-PnPSubWebs to get my web object before calling Add-@PnPFile and that seems to work.

I think it it your firstweb... maybe you fill in the whole path.

Hi @Pieter Veenstra, first of all, thank you for your fast response...

 

I've tried  this code instead 4-5 lines and Pages upload ok. Thank you!!

foreach ($subweb in Get-PnPSubWebs ) {
	Add-PnPFile -Path $file -Folder "/Pages"  -Web $subweb
}