Powershell for SPO - need to remove a user

some1somewhere 1 Reputation point
2021-12-13T22:45:57.4+00:00

I have been provided the following:

The recommended Powershell script in removing Secondary Site Collection Admin for all OneDrive for Business users is as follows:

Can you confirm this looks correct to REMOVE a secondary site admin from several sites ?
Where am I substituting our info - it's not completely clear to me which are vars for the script and which are examples.
is ******@Tenantname.onmicrosoft.com the email address of the global admin running the script or the secondary admin to be removed - does it need to be a .onmicrosoft.com email and not the @companydomain.tld email ?

Function Add-OnedriveSecondaryAdmin($AdminURL,$SecondaryAdmin)
{
    #connect Spo service.
    Connect-SPOService -Url $AdminURL
    #Get all Onedrive URL's.
    $OneDriveURLs = Get-SPOSite -IncludePersonalSite $true -Limit All -Filter "Url -like '-my.sharepoint.com/personal/'"
    foreach($OneDriveURL in $OneDriveURLs)
    {
        #Add Secondary administrator to Onedrive Site.
        Set-SPOUser -Site $OneDriveURL.URL -LoginName $SecondaryAdmin -IsSiteCollectionAdmin $false-ErrorAction SilentlyContinue
        Write-Host "Added secondary admin to the site $($OneDriveURL.URL)" 
    }
}
Add-OnedriveSecondaryAdmin -SecondaryAdmin "******@Tenantname.onmicrosoft.com" -AdminURL "https://Tenantname-admin.sharepoint.com"
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Allen Xu_MSFT 13,861 Reputation points
    2021-12-14T02:51:02.473+00:00

    Hi @some1somewhere ,

    As per my test, yes it is correct to remove a secondary site admin from several OneDrive for Bussiness personal sites if the secondary admin is the same person (all with the same email address). You only need to replace the values of parameters SecondaryAdmin and AdminURL.
    157353-image.png

    "******@Tenantname.onmicrosoft.com" should be replaced with the email address the secondary admin to be removed, "https://Tenantname-admin.sharepoint.com" should be replaced with URL of SharePoint Online admin center.

    ----------

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.