0

I work at a school and have a script to create sites, users and folders automatically. In the finaI steps of the script I need to copy a page from a Sharepoint to another and make it the homepage, but I can't and have been stuck...

Here's what I have so far...

 $cred = Get-Credential
 Connect-PnPOnline -Url https://acme.sharepoint.com/sites/sitewiththepagemodel -Credentials  $cred
 $tempFile = [System.IO.Path]::GetTempFileName();

 Export-PnPPage -Identity "Bem-vindo-ao-site-da-Turma.aspx" -Force -Out $tempFile
 
 Connect-PnPOnline -Url "https://acme.sharepoint.com/sites/sitebeingcreated" -Credentials  $cred
 Apply-PnPProvisioningTemplate -Path $tempFile
 Set-PnPHomePage -RootFolderRelativeUrl Bem-vindo-ao-site-da-Turma.aspx

But the above code says

Apply-PnPProvisioningTemplate : The term 'Apply-PnPProvisioningTemplate' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try again.

I used to had an error on Export-PNPPage, reinstall and now it's the Apply-PnPProvisioningTemplate that's not working. Does this exist in the last version? Also, is there an easier way to do this?

Thanks a lot for your kind help. I'm not very good at Powershell, so please be gentle! ;)

3 Answers 3

0

If you have installed PnP.PowerShell Module, then also need to install SharePointPnPPowerShellOnline Module, as Apply-PnPProvisioningTemplate is hosting in SharePointPnPPowerShellOnline Module, check this capture:

enter image description here

Install using this command:

Install-Module -Name SharePointPnPPowerShellOnline -RequiredVersion 3.29.2101.0 -AllowClobber

Then rerun the PowerShell script, the error "Apply-PnPProvisioningTemplate : The term 'Apply-PnPProvisioningTemplate' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." will gone.

0

As Jerry mentioned, Apply-PnPProvisioningTemplate was renamed in the new PowerShell module PnP.PowerShell. You can install the old module, or you can try to update the script to work with the new module. For instance, that command is now Invoke-PnPSiteTemplate

0

Well, thanks to you I solved my problem...

Here it is for someone in the future and for future reference to anyone who needs to copy one page from one site to another...

$cred = Get-Credential
Connect-PnPOnline -Url https://acme.sharepoint.com/sites/sitewiththepagemodel -Credentials  $cred
$tempFile = [System.IO.Path]::GetTempFileName();

Export-PnPPage -Identity "Bem-vindo-ao-site-da-Turma.aspx" -Force -Out $tempFile
 
Connect-PnPOnline -Url "https://acme.sharepoint.com/sites/sitebeingcreated" -Credentials  $cred
Invoke-PnPSiteTemplate -Path $tempFile
Set-PnPHomePage -RootFolderRelativeUrl Bem-vindo-ao-site-da-Turma.aspx

You guys Rock!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.