-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPO-DelegateManagerOneDrive.ps1
26 lines (20 loc) · 1.02 KB
/
SPO-DelegateManagerOneDrive.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Install Module - https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets
Install-Module -Name "PnP.PowerShell"
# Consent if its your first time
Register-PnPManagementShellAccess
#Set Variables
$Creds = (Get-Credential)
$Tenant = read-host -prompt "Enter in your Microsoft Tenant (ex. Company.onmicrosoft.com would be Company)"
$SiteURL = ("https://" + $Tenant + ".sharepoint.com")
$AdminSiteURL= ("https://" + $Tenant + "-admin" + ".sharepoint.com")
$UserAccount = Read-Host -Prompt "Enter in the Users UPN"
$UserMgr = (Get-AzureADUserManager -ObjectId $UserAccount).UserPrincipalName
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Creds
#Get all properties of a User Profile
$UserProfile = Get-PnPUserProfileProperty -Account $UserAccount
# Match Up Collected Information into Variables
$OneDriveSiteUrl = $UserProfile.PersonalUrl
#Change OneDrive Ownership
Connect-PnPOnline -Url $AdminSiteURL -Credentials $Creds
Set-PnPTenantSite -Url $OneDriveSiteUrl -Owners $UserMgr