Hi AB123, per my knowledge, currently, you can only create folders for one user in OneDrive with the following script.
#Load SharePoint Online CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
$FolderName = "Archives"
#Setup Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($OneDriveSiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the default "Documents" Library
$List = $Ctx.Web.Lists.GetByTitle("Documents")
#Check if Folder Exists already
$Folders = $List.RootFolder.Folders
$Ctx.Load($Folders)
$Ctx.ExecuteQuery()
#Get existing folder names
$FolderNames = $Folders | Select -ExpandProperty Name
if($FolderNames -contains $FolderName)
{
write-host "Folder Exists Already!" -ForegroundColor Yellow
}
else
{
#onedrive for business powershell create folder
$NewFolder = $List.RootFolder.Folders.Add($FolderName)
$Ctx.ExecuteQuery()
Write-host "Folder '$FolderName' Created Successfully!" -ForegroundColor Green
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Hope this helps.
Best Regards.
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.