If you’ve ever found yourself stuck with an organization assets library in SharePoint that won’t go away, even after the site it was created on has been deleted, you’re in the right place. Normally, you’d use the Remove-PnPOrgAssetsLibrary
command, but it needs the -LibraryUrl
parameter, which we can’t get if the site is gone. Don’t worry – I’ve got a solution for you. Let’s walk through it together!
Steps to Remove the Stuck Library
Here is the code to do that:
1 | $orgAssetsLib = Get-PnPOrgAssetsLibrary -ErrorAction SilentlyContinue |
Explanation
Retrieve Organization Assets Library Information: We use
Get-PnPOrgAssetsLibrary
to get information about the organization assets libraries and create an empty array.Handle Single and Multiple Libraries: PowerShell converts an array with a single element into the object itself rather than an array. We check if the command returned only one Org Assets Library object and put the ID of the library inside the array we created previously. Otherwise, we select the IDs of all the libraries and put them in the array. Notice how in both cases we only take the libraries with an empty
LibraryUrl
. This indicates that it is a library lost in limbo.Remove Libraries: Iterate through the IDs and call the
/_api/Microsoft.Online.SharePoint.TenantManagement.Office365Tenant/RemoveFromOrgAssets
endpoint with the ID of the broken Organization Asset Library to remove it.
And that’s it! By following these steps, you can successfully remove that pesky organization assets library, even if the original site is long gone. This method bypasses the need for the -LibraryUrl
parameter, keeping your SharePoint environment clean and tidy.
Feel free to reach out if you have any questions or run into any issues.
Hope you find this useful.