PowerShell: Using Invoke-PnPTenantTemplate with Verbose Error Handling for Office 365 Tenant Template Transfers
In this article, we will explore how to use the Invoke-PnPTenantTemplate cmdlet in PowerShell 7.0 version 7.3.4 to transfer a site template between two Office 365 tenants. We will also cover key concepts such as error handling and verbose mode, which will help you troubleshoot any issues that may arise during the transfer process.
Prerequisites
Before we begin, make sure you have the following prerequisites:
- A source and destination Office 365 tenant
- PowerShell 7.0 version 7.3.4 or later
- The SharePoint Online Management Shell
- The PnP PowerShell module
Connecting to the Source Tenant
To connect to the source tenant, use the following command:
Connect-PnPOffice365 -Url -Credential (Get-Credential) Replace with the URL of your source tenant. This command will prompt you to enter your credentials for the source tenant.
Exporting the Site Template
Once you are connected to the source tenant, you can export the site template using the following command:
Get-PnPSiteTemplate -Out C:\temp\sourceSiteTemplate.pnp -ForceThis command will export the site template to a file named sourceSiteTemplate.pnp in the C:\temp directory. The -Force parameter is used to overwrite any existing files with the same name.
Transferring the Site Template to the Destination Tenant
To transfer the site template to the destination tenant, first connect to the destination tenant using the following command:
Connect-PnPOffice365 -Url -Credential (Get-Credential) Replace with the URL of your destination tenant. This command will prompt you to enter your credentials for the destination tenant.
Next, use the following command to apply the site template to a new site in the destination tenant:
Invoke-PnPSiteTemplate -Identity C:\temp\sourceSiteTemplate.pnp -OutParameter NewSiteUrlThis command will apply the site template and return the URL of the new site in the NewSiteUrl variable. You can then use this variable to navigate to the new site.
Verbose Error Handling
To enable verbose error handling, use the -Verbose parameter when calling the Invoke-PnPTenantTemplate cmdlet. This will provide detailed information about any errors that occur during the transfer process, making it easier to troubleshoot any issues.
Invoke-PnPSiteTemplate -Identity C:\temp\sourceSiteTemplate.pnp -OutParameter NewSiteUrl -VerboseIn this article, we have covered how to use the Invoke-PnPTenantTemplate cmdlet in PowerShell 7.0 version 7.3.4 to transfer a site template between two Office 365 tenants. We have also covered key concepts such as error handling and verbose mode, which will help you troubleshoot any issues that may arise during the transfer process.