Hi,
I'm new to powershell and sharepoint. I can add a publishingpage to sharepoint using powershell. Now I also want to remove the publishingpage using powershell, but that is the part I don't seem to get to work.
#Config Variables $SiteURL = "https://somesharepointsite" $PageName = "1234.aspx" $PageTitle= "SomeTitle" $PageTemplate = "BlankWebPartPage" $PageContent="somecontent" $VacancyHours=36 $SomeId="123456" #Get Credentials to connect #$Cred = Get-Credential Try { #Connect to PNP Online Connect-PnPOnline -Url $SiteURL -Credentials $Cred #Create a publishing page Add-PnPPublishingPage -PageName $PageName -Title $PageTitle -PageTemplateName $PageTemplate #Get the Page $Page = Get-PnPListItem -List "Pages" -Query "<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>$PageName</Value></Eq></Where></Query></View>" #check-out the page for editing Set-PnPFileCheckedOut -Url $Page["FileRef"] #Set Content Type Set-PnPListItem -List "Pages" -Identity $Page -ContentType "Vacancy" #Set Page Content Set-PnPListItem -List "Pages" -Identity $Page -Values @{"PublishingPageContent"=$PageContent; "VacancyHours"=$VacancyHours; "SomeId"=$SomeId} #check-in the page Set-PnPFileCheckedIn -Url $Page["FileRef"] -CheckinType MajorCheckIn } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red }
After I made the page, I want to remove it again. I think it's something with remove-pnplistitem, but i cannot get it to work. Among other things I tried:
#Remove publishing page Remove-PnPListItem -List "Pages" -Identity $PageNameThanks in advance.