Powershell Version: 7.4.1 PnP version: PnP.PowerShell 2.4.0 I am trying to create pages from Sharepoint template using following function.
function New-ArticlePage {
param (
$PageName,
$PageTitle,
$PageSubHeader
)
$TemplateURL = "Templates/article-template.aspx"
Connect-PnPOnline -Url $SharepointSite -Interactive
$Template = Get-PnPPage -Identity $TemplateURL
Remove-PnPPage -Identity $PageName -Force
$Template.Save($PageName)
Set-PnPPage -Identity $PageName -Title $PageTitle | out-null
Set-PnPPageTextPart -Page $PageName -InstanceId 1fca516d-4584-448d-8fff-2c0d5ab10318 -Text PageSubHeader
}
If I execute the function from a Button click event, the execution halts at following line
$Template = Get-PnPPage -Identity $TemplateURL
Button code:
$Button_CreatePage = New-Object System.Windows.Forms.Button
$Button_CreatePage.Location = New-Object System.Drawing.Point(100,335)
$Button_CreatePage.Size = New-Object System.Drawing.Size(195,23)
$Button_CreatePage.Text = "Create Page"
$Groupbox_ArticleTemplateModel.Controls.Add($Button_CreatePage)
$Button_CreatePage.Add_Click(
{
New-ArticlePage -PageName $Textbox_PageName.Text -PageTitle $Textbox_PageTitle.Text -PageSubHeader $Textbox_PageSubHeader.Text
}
)
If I execute the function directly with params it creates page as expected. But if I place the same code inside Add_click function it halts at Get-PnPPage -Identity $TemplateURL
New-ArticlePage -PageName $PageName -PageTitle $PageTitle -PageSubHeader $PageSubHeader