1

I'm trying to add organizational asset library but it fails as Unauthorized operation tried both SPO and PnP cmdlets.

$AssetsLibraryURL ="https://tenant.sharepoint.com/sites/Site/Kuvapankki"
$AssetsDocLibraryURL = "https://tenant.sharepoint.com/sites/Site/Dokumenttipohjat"
$ThumbnailUrl = "https://tenant.sharepoint.com/sites/Site/Kuvapankki/300w/Badge-Turqoise.png"

Connect-SPOService https://tenant-admin.sharepoint.com
Add-SPOOrgAssetsLibrary -LibraryUrl $AssetsLibraryURL -ThumbnailUrl $ThumbnailUrl -OrgAssetType ImageDocumentLibrary
Add-SPOOrgAssetsLibrary -LibraryUrl $AssetsDocLibraryURL -ThumbnailUrl $ThumbnailUrl -OrgAssetType OfficeTemplateLibrary

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/Kassler -UseWebLogin   
Add-PnPOrgAssetsLibrary -LibraryUrl $AssetsLibraryURL -ThumbnailUrl $ThumbnailUrl -OrgAssetType ImageDocumentLibrary
Add-PnPOrgAssetsLibrary -LibraryUrl $AssetsDocLibraryURL -ThumbnailUrl $ThumbnailUrl -OrgAssetType OfficeTemplateLibrary

Both cmdlets return the same error

Add-SPOOrgAssetsLibrary : Attempted to perform an unauthorized operation.
At line:1 char:1
Add-SPOOrgAssetsLibrary -LibraryUrl $AssetsDocLibraryURL  -ThumbnailU ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo          : NotSpecified: (:) [Add-SPOOrgAssetsLibrary], ServerUnauthorizedAccessException
    FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerUnauthorizedAccessException,Microsoft.Online.SharePoint.PowerShell.AddSPOOrgAssetsLibrary

Add-PnPOrgAssetsLibrary : Attempted to perform an unauthorized operation.
At line:1 char:1
Add-PnPOrgAssetsLibrary -LibraryUrl $AssetsLibraryURL -ThumbnailUrl $ ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CategoryInfo          : WriteError: (:) [Add-PnPOrgAssetsLibrary], ServerUnauthorizedAccessException
    FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Admin.AddOrgAssetsLibrary

Both SPO PowerShell and PnP PowerShell are in latest version and using Global Admin account.

Sample of running the script

2 Answers 2

1

Figured this out. Even as Global Admin I needed to add myself as owner of the site. Once I added owner permissions the error changed to

Add-PnPOrgAssetsLibrary : "Everyone except external users" needs to be given read permission to the document library.

This after adding the system group to the asset library (as was described in Microsoft documentation) it did add it as asset library.

Thus the solution to this is to have sufficient permissions to the org asset site, as in this case GA did not have enough access to the site collection.

3
  • I got to this step, now I receive the error "This library is not on the site that contains other organization asset libraries." Jan 28 at 23:26
  • Did you try creating the library on different site than other asset libraries? As per Microsoft documentation (learn.microsoft.com/en-us/sharepoint/…) "All organization asset libraries must be on the same site". If you tried adding library from other site, that might be the cause.
    – Kim B
    Jan 30 at 7:00
  • I discovered that somebody at my org had already created a asset library and you can only have one site with this designation. The cmdlet that helped me discover this was Get-PnPOrgAssetsLibrary Feb 1 at 0:41
0

According to my research, the Organization Assets library located in the site collection (top level site)

For example:

$AssetsLibraryURL ="https://tenant.sharepoint.com/sites/sitename"

My Test:

#Config Parameter
$AdminSiteURL= "https://tenant-admin.sharepoint.com"
$SiteURL = "https://tenant.sharepoint.com/sites/TeamSite1"
$LibraryUrl = "https://tenant.sharepoint.com/sites/TeamSite1/OrgAssets"
$ThumbnailURL = "https://tenant.sharepoint.com/sites/TeamSite1/SiteAssets/icon.png"   
 
#Get credentials to connect
$Credential = Get-Credential
  
#Connect to SharePoint Online services
Connect-SPOService -url $AdminSiteURL -Credential $credential
 
#Create Organization Asset Library
Add-SPOOrgAssetsLibrary -LibraryUrl $LibraryUrl -ThumbnailUrl $ThumbnailURL

enter image description here

3
  • 1
    Your example differs from mine only by using basic credentials. I'm connecting with modern auth as MFA is required. You set SiteURL variable but it is not actually used in the set up.
    – Kim B
    Aug 18, 2021 at 8:34
  • Hi Kim B. You set SiteURL value is "tenant.sharepoint.com/sites/Site/Kuvapankki" Can I understand that “Site” is top level site and "Kuvapankki" is sub site? Your Organization Assets library located in sub site? Aug 18, 2021 at 9:46
  • Kuvapankki is the name of the document library. "Image bank" if translated to English.
    – Kim B
    Aug 18, 2021 at 9:49

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.