Omar El-Anis – 365 Developer

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

OneDrive

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 = "someone@domain.com"<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+'@emaildomain.co.uk'</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 = 'https://tenant-my.sharepoint.com/personal/'+$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 https://tenant-admin.sharepoint.com -Credential $cred<br>
Set-SPOSite -Identity $URL -Owner $newUserEmail -NoWait</p>
<p>

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments