You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PS C:\Users\User1> # Connect to the SharePoint Online tenant administration site
PS C:\Users\User1> Connect-PnPOnline -Url "https://mytenant-admin.sharepoint.com" -Interactive
PS C:\Users\User1>
PS C:\Users\User1> # Define the site script
PS C:\Users\User1> $siteScript = @{
Title = "Project Documents Template"
Description = "Script for creating a project documents library with subfolders"
Content = '{
"schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
"actions": [
{
"verb": "createSPList",
"listName": "Project Name - Project Document",
"templateType": 101,
"subactions": [
{
"verb": "setDescription",
"description": "This is a project documents library."
}
]
}
],
"bindata": {},
"version": 1
}'
}
PS C:\Users\User1>
PS C:\Users\User1> # Add the site script
PS C:\Users\User1> $siteScriptObject = Add-PnPSiteScript @sitescript
PS C:\Users\User1>
PS C:\Users\User1> # Debugging output to verify site script creation
PS C:\Users\User1> Write-Host "Site script object: $($siteScriptObject | Out-String)"
Site script object:
Id Title Version Description Content IsSiteScriptPackage
0f13736c-bbcd-4c7e-87d5-2a38f1b7d301 Project Documents Template 0 Script for creating a project documents library with subfolders False
PS C:\Users\User1>
PS C:\Users\User1> if ($siteScriptObject -eq $null) {
Write-Host "Error: Failed to create site script. Exiting script." -ForegroundColor Red
}
PS C:\Users\User1>
PS C:\Users\User1> # Debugging output to verify web URL
PS C:\Users\User1> $webUrl = "https://mytenant.sharepoint.com/sites/SPMigrationTest"
PS C:\Users\User1> Write-Host "Web URL: $webUrl"
Web URL: https://mytenant.sharepoint.com/sites/SPMigrationTest
PS C:\Users\User1>
PS C:\Users\User1> # Debugging output to verify site script object
PS C:\Users\User1> Write-Host "Site script object: $($siteScriptObject | Out-String)"
Site script object:
Id Title Version Description Content IsSiteScriptPackage
0f13736c-bbcd-4c7e-87d5-2a38f1b7d301 Project Documents Template 0 Script for creating a project documents library with subfolders False
PS C:\Users\User1>
PS C:\Users\User1> # Check if $siteScriptObject is null
PS C:\Users\User1> if (-not $siteScriptObject) {
Write-Host "Error: Site script object is null. Exiting script." -ForegroundColor Red
exit
}
PS C:\Users\User1>
PS C:\Users\User1> # Check if the site script is available in the site collection
PS C:\Users\User1> $availableSiteScripts = Get-PnPSiteScript
PS C:\Users\User1> $siteScriptStatus = $availableSiteScripts | Where-Object { $_.Id -eq $siteScriptObject.Id }
PS C:\Users\User1>
PS C:\Users\User1> if (-not $siteScriptStatus) {
Write-Host "Error: Site script is not available. Exiting script." -ForegroundColor Red
exit
}
PS C:\Users\User1>
PS C:\Users\User1> # Debugging output to verify parameters
PS C:\Users\User1> Write-Host "Site script object ID: $($siteScriptObject.Id)"
Site script object ID: 0f13736c-bbcd-4c7e-87d5-2a38f1b7d301
PS C:\Users\User1> Write-Host "Web URL: $webUrl"
Web URL: https://mytenant.sharepoint.com/sites/SPMigrationTest
PS C:\Users\User1>
PS C:\Users\User1> # Invoke the site script directly
PS C:\Users\User1> Write-Host "Invoking site script..."
Invoking site script...
PS C:\Users\User1> Invoke-PnPSiteScript -Identity $siteScriptObject.Id -WebUrl $webUrl
Invoke-PnPSiteScript: Object reference not set to an instance of an object.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
PS C:\Users\User1> # Connect to the SharePoint Online tenant administration site
PS C:\Users\User1> Connect-PnPOnline -Url "https://mytenant-admin.sharepoint.com" -Interactive
PS C:\Users\User1>
PS C:\Users\User1> # Define the site script
PS C:\Users\User1> $siteScript = @{
0f13736c-bbcd-4c7e-87d5-2a38f1b7d301 Project Documents Template 0 Script for creating a project documents library with subfolders False
PS C:\Users\User1>
PS C:\Users\User1> if ($siteScriptObject -eq $null) {
0f13736c-bbcd-4c7e-87d5-2a38f1b7d301 Project Documents Template 0 Script for creating a project documents library with subfolders False
PS C:\Users\User1>
PS C:\Users\User1> # Check if $siteScriptObject is null
PS C:\Users\User1> if (-not $siteScriptObject) {
Anyone run into this issue?
Beta Was this translation helpful? Give feedback.
All reactions