Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-PnPSiteTemplate -Path $FilePath -ErrorAction Stop -WarningAction SilentlyContinue - Error Message: Attempted to perform an unauthorized operation. #224

Closed
BrandtC-NAIT opened this issue Jul 15, 2024 · 13 comments
Assignees
Labels
status: fixed For the issues that are fixed

Comments

@BrandtC-NAIT
Copy link

I debug ran the script and here is what happened:

[PS] 'C:\Users\---MY LOGIN---\Documents\One-Offs\TEOC\microsoft-teams-emergency-operations-center\Deployment\provisioning\EOC-Provision.ps1'

Enter site template XML schema file path: C:\Users\---MY LOGIN---\Documents\One-Offs\TEOC\microsoft-teams-emergency-operations-center\Deployment\provisioning\EOC-SiteTemplate.xml
C:\Users\op.brandtc\Documents\One-Offs\TEOC\microsoft-teams-emergency-operations-center\Deployment\provisioning\EOC-SiteTemplate.xml
Enter tenant name: (contoso): ---OUR TENANT---
Enter tenant admin email: ---A VALID EMAIL IS HERE---
Enter site name. Allowed characters for site name are underscore, dashes, single quotes, and periods (_,-,',.), and can't start or end with a period.: Facilities_Emergency_Management
PnP.PowerShell module found

Checking if site already exists at /sites/Facilities_Emergency_Management

Site doesn't exist, creating new site at /sites/Facilities_Emergency_Management

https://---OUR TENANT---.sharepoint.com/sites/Facilities_Emergency_Management

Creating lists in Facilities_Emergency_Management site

Error Message:  Attempted to perform an unauthorized operation.

It fails on this line of code, line #66:
Invoke-PnPSiteTemplate -Path $FilePath -ErrorAction Stop -WarningAction SilentlyContinue

I've moved the File around to different locations to make sure the file is accessible. Tried running the script an non & privileged PowerShell.

NOTE: any ---VALUE PLACEHOLDER--- is me removing the content for security reasons in this post.

@v-saikirang
Copy link
Collaborator

Hi @BrandtC-NAIT,

Thanks for reaching out to us.

Please ensure that you are executing these scripts on PowerShell 7.2 or later, as it is a prerequisite for using PnP PowerShell. Additionally, update PnP PowerShell and attempt to run the scripts again.

https://pnp.github.io/powershell/articles/installation.html

Please let us know if this worked.

Thanks.

@BrandtC-NAIT
Copy link
Author

Same issue under PowerShell 7.4.1 and Updated PnP Module

Error Message: Attempted to perform an unauthorized operation.

@v-saikirang
Copy link
Collaborator

Hi @BrandtC-NAIT,

Can you please try creating a different site name without under scores
"Enter site name. Allowed characters for site name are underscore, dashes, single quotes, and periods (_,-,',.), and can't start or end with a period.: Facilities_Emergency_Management"

@BrandtC-NAIT
Copy link
Author

Tried that, no spaces, only Mixed Caps: FacilitiesEmergencyManagement

@v-saikirang
Copy link
Collaborator

Hi @BrandtC-NAIT,

Can you please check if the SP site is created and if any lists are created.

@BrandtC-NAIT
Copy link
Author

As reported by the SharePoint Team: https://imgur.com/a/SebYcA8](url)

@v-saikirang
Copy link
Collaborator

Hi @BrandtC-NAIT,

Can you please share a screenshot directly here instead of the link.

Thanks.

@BrandtC-NAIT
Copy link
Author

image (6)
image (5)
image (4)
image (3)
image (2)
image (1)
image

@BrandtC-NAIT
Copy link
Author

BrandtC-NAIT commented Jul 23, 2024

Hi @BrandtC-NAIT,

Can you please share a screenshot directly here instead of the link.

Thanks.

Shared as requested. @v-saikirang

@v-saikirang
Copy link
Collaborator

v-saikirang commented Jul 24, 2024

Hi @BrandtC-NAIT,

Thanks for sharing the screenshots. Please make sure you are added as site collection admin to the share point site and try to tweak the script to run only the lists creation. Update the URL variable with full site URL since the site is already created.
Can you also share the PNP power shell version.

Connect-PnPOnline -Url $TenantURL$EOCSiteURL -Interactive

Write-Host "Creating lists in $SiteName site"

Invoke-PnPSiteTemplate -Path $FilePath -ErrorAction Stop -WarningAction SilentlyContinue
      
Write-Host "App Provision complete."

@BrandtC-NAIT
Copy link
Author

BrandtC-NAIT commented Jul 26, 2024

2.5.0 PnP.PowerShell

Hardcoding in the path with the below changes did the trick:
`
# $site = Get-PnPTenantSite -Url $TenantURL$EOCSiteURL -ErrorAction SilentlyContinue

# if ($null -ne $site) {
#     Write-Host "Site already exists, exiting the PowerShell script"
#     return;
# }
# else {
#     Write-Host "Site doesn't exist, creating new site at $EOCSiteURL"
# }

# try {
#     if (($TenantURL + $EOCSiteURL).Length -lt 128) {
#         New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title $SiteName -Url $TenantURL$EOCSiteURL -Owner $AdminEmail -ErrorAction Stop -WarningAction SilentlyContinue
#     }
#     else {
#         Write-Host "Site creation failed. Site URL cannot have more than 128 characters." -ErrorAction Stop
#         return
#     }
# }
# catch {
#     Write-Host "`nError Message: " $_.Exception.Message
#     Write-Host "Site creation failed. Site name cannot contain symbols other than underscore, dashes, single quotes, and periods (_,-,',.), and can't start or end with a period."
#     return;

# }

$TenantURLEOCSiteURL = "https://---OUR TENANT---.sharepoint.com/sites/FacilitiesEmergencyManagement"

Connect-PnPOnline -Url $TenantURLEOCSiteURL -Interactive

Write-Host "Creating lists in $SiteName site"

Invoke-PnPSiteTemplate -Path $FilePath -ErrorAction Stop -WarningAction SilentlyContinue
      
Write-Host "App Provision complete."`

NOTE: any ---VALUE PLACEHOLDER--- is me removing the content for security reasons in this post.

@v-saikirang
Copy link
Collaborator

Hi @BrandtC-NAIT,

So as i understand the issue is cleared now. Please confirm if i can close the ticket.
Thanks.

@BrandtC-NAIT
Copy link
Author

@v-saikirang please do close the ticket. Issue is now resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: fixed For the issues that are fixed
Projects
None yet
Development

No branches or pull requests

2 participants