Hi @DWTK ,
Your requirement can be achieved via PnPPowershell.
It is important to note that user’s OneDrive account is private by default. Even Global Office 365 administrators do not have access to other users’ OneDrive. We need to grant the user admin access to all OneDrive sites before creating folder in these sites.
Please follow the steps:
1,Grant Admin Access to All OneDrive for Business
#Set Parameters
$AdminSiteURL="https://tenant-admin.sharepoint.com"
$SiteCollAdmin="******@tenant.onmicrosoft.com"
#Connect to PnP Online to the Tenant Admin Site
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get All OneDrive Sites
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
#Loop through each site
ForEach($Site in $OneDriveSites)
{
#Add Site collection Admin
Set-PnPTenantSite -Url $Site.URL -Owners $SiteCollAdmin
Write-Host -f Green "Added Site Collection Admin to: "$Site.URL
}
2, Then, please run the below PowerShell script to create folder to all OneDrive as an admin.
#Parameters
$AdminCenterURL = "https://tenant-admin.sharepoint.com"
$FolderName = "Archives"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Connect to Admin Center
Connect-PnPOnline -Url $AdminCenterURL -Credential $Cred
#Get All OneDrive sites
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
#Iterate through Each OneDrive
ForEach($Site in $OneDriveSites)
{
Try {
Write-host -f Yellow "Ensuring Folder '$FolderName' in $($Site.URL)" -NoNewline
#Connect to OneDrive site
$SiteConn = Connect-PnPOnline -Url $Site.URL -Credential $Cred -ReturnConnection -ErrorAction Stop
#ensure folder in SharePoint Online using powershell
$NewFolder = Resolve-PnPFolder -SiteRelativePath "Documents/$FolderName" -Connection $SiteConn -ErrorAction Stop
Disconnect-PnPOnline -Connection $SiteConn
Write-host -f Green " Done!"
}
Catch {
write-host "`tError: $($_.Exception.Message)" -foregroundcolor Red
}
}
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
3, Remove user admin access from all OneDrive sites.
#Set Parameters
$AdminSiteURL="https://tenant-admin.sharepoint.com"
$SiteCollAdmin="******@tenant.onmicrosoft.com"
#Connect to PnP Online to the Tenant Admin Site
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get All OneDrive Sites
$OneDriveSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
#Loop through each site
ForEach($Site in $OneDriveSites)
{
Connect-PnPOnline $_.Url -Credentials $Cred
$User = Get-PnPUser | Where { $_.LoginName -like $LoginID}
If($User -ne $Null)
{
Remove-PnPSiteCollectionAdmin -Owners $LoginID
Write-Host "`tRemoved user from Site Collection Administrator Group!" -f Green
}
Thanks,
Yanli Jiang
===========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.
Updated on 2022.05.30
This user account should be a global admin, otherwise it does not have permission to enter the SharePoint admin center, and therefore has no permission to grant permission. If the account does not have this permission, you can ask your administrator to assign this permission to you.
$SiteCollAdmin="******@tenant.onmicrosoft.com"
Thanks,
Yanli Jiang
===========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.
Updated on 2022.05.31
The "-Interactive" switch is required if connecting to PnPOnline with an MFA-enabled account. This part of the script in the answer contains the "-Interactive" switch.
#Connect to PnP Online to the Tenant Admin Site
Connect-PnPOnline -Url $AdminSiteURL -Interactive
The reason for your previous problem is the account's permission, not related to MFA.
Thanks,
Yanli Jiang
===========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.
Updated on 2022.06.02
This may be related to your account is not global admin. I used an account that is not a global admin to test, and the same error as you appeared.
You can check whether the account you are using is a global admin.
Go to Microsoft 365 admin center
You can see that the account I used in the previous test was the global admin account.
You can edit the user's role by clicking "Manage roles".
Thanks,
Yanli Jiang
===========================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.