[SOLVED] [SPO] remove site admin. if user already been removed

MaartenK 101 Reputation points
2021-08-24T14:08:07.153+00:00

A customer has the follow problem. A employee has left the company and the account is removed. That`s fine no problem. the only problem is the user was a site admin. Now the user is removed and we found out that we cannot remove the user with powershell only by hand and the user was also owner of all Onedrive sites :-( (not good I know, I just fined this out myself)

How can we remove this "unknow" user from existing sites?
$OneDriveSiteURL = "https://SITE-my.sharepoint.com/personal/user_com"
$UserAccount = "unknowuser@keyman .com"
$Site = Get-SPOSite $OneDriveSiteURL
Set-SPOUser -Site $Site -LoginName $UserAccount -IsSiteCollectionAdmin $False

error message
Set-SPOUser : The user does not exist or is not unique.
126019-2021-08-24-16-01-37-window.png

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Accepted answer
  1. MaartenK 101 Reputation points
    2021-09-01T07:02:43.327+00:00

    Hi Emily,

    I found the reason why this user had all these permissions. The customer was using the tool ShareGate. There is an rather scary option in ShareGate (IMO) to gain automatically Site Collection admin permissions.
    The user did not removed his permission.

    I was able to get an license and reproduce this. I removed the user with the same tool. So I would thank you for your help. I will certainly use you part of the PS script if needed.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2021-08-25T08:05:16.297+00:00

    @MaartenK

    You could run following PowerShell to remove orphaned OneDrive secondary site collection administrator.

    $SiteURL = "https://SITE-my.sharepoint.com/personal/user_com"      
    $UserID="i:0#.f|membership|******@domain.com"      
    Connect-PnPOnline -Url $SiteURL -credential (Get-Credential)  
    Remove-PnPUser -Identity $UserID -Force   
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.