Forum Discussion
María José Pedreira
Apr 24, 2017Brass Contributor
Upload Pages using Powershell / PnP
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!
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.
- Deleted
I think it it your firstweb... maybe you fill in the whole path.
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.
- María José PedreiraBrass Contributor
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
}