Skip to content

Instantly share code, notes, and snippets.

@plamber
Last active May 15, 2021 12:07
Show Gist options
  • Save plamber/bac2456f1dca2bdfc51d52a02f2339fa to your computer and use it in GitHub Desktop.
Save plamber/bac2456f1dca2bdfc51d52a02f2339fa to your computer and use it in GitHub Desktop.
Remove user from site collection and add a new site collection owner
$userToAdd = "<upnOfUserToAdd>"
$userToRemove = "<upnOfUserToRemove>"
$webUrl = "<spoUrl>"
$m365Status = m365 status
Write-Host $m365Status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
$m365Status = m365 status
}
m365 spo user remove --webUrl $webUrl --loginName "i:0#.f|membership|$userToRemove" --confirm
m365 spo site classic set --url $webUrl --owners $userToAdd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment