Omar El-Anis – 365 Developer

My experiences with SharePoint, Flows, PowerApps, JavaScript and all of the other lovely web technologies out there!


Add a site owner to a OneDrive Account

If you need to programmatically add a user as a site owner to a OneDrive site (granting that person access to the other users OneDrive and all of their files) then use the following PowerShell script:

$username = ""<br>
$password = Read-Host -Prompt "Please enter your password" -AsSecureString<br>
$oldUser = Read-Host 'What is the username of the person who has left the company? NOTE: replace any full stops "." with "_" '<br>
$newUser = Read-Host 'What is the username of the new owner?'<br>
$newUserEmail = $newUser+''</p>
<p>#update the tenant field and the e-mail domain in the URL below to match the same format the OneDrive URL currently follows:<br>
$URL = ''+$newUser +'_EMAILDOMAIN_co_uk'<br>
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)<br>
#Change the tenant text below to point to your tenancy<br>
Connect-SPOService -Url -Credential $cred<br>
Set-SPOSite -Identity $URL -Owner $newUserEmail -NoWait</p>

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments