Pages

Tuesday, April 14, 2026

Provisioning a 365 user from a powershell one at a time

" We can’t show the OneDrive settings. If this is a new user, their OneDrive might not be set up yet. Try again in a few minutes. "


I tried to provision my new users using scripts, but I got nowhere.  So I used the following script.  I had to do with on a PER user basis, but is what it is.  (Created an AutoHotkey macro to do the actual work for me since I had a few hundred users)

If its a new user, the user has to "soak in 365" for a few hours before this will sometimes work.  
Ensure that you have the proper licenses in place for the user

1>
Create a file "singleconvert.ps1" and put in the code below.  Replace TENANT ID and COMPANYINC with your information.  Bottom of this page shows were to find Tenant ID
Param(
    [Parameter(Mandatory = $False)]
    [String]$SharepointURL = "https://COMPANYINC-admin.sharepoint.com/",

    [Parameter(Mandatory = $False)]
    [String]$tenantID = "TENANTID",

    [Parameter(Mandatory = $True)]
    [String]$UserEmail = ""
)

# Connect to services
Connect-MgGraph -TenantId $tenantID -Scopes 'User.Read.All'
Connect-SPOService -Url $SharepointURL

Write-Host "Checking if user $UserEmail exists..."

try {
    $u = Get-MgUser -UserId $UserEmail -Select UserPrincipalName, AssignedLicenses

    if ($u) {
        Write-Host "User found. Requesting OneDrive provisioning for $($u.UserPrincipalName)..."

        Request-SPOPersonalSite -UserEmails @($u.UserPrincipalName) -NoWait

        Write-Host "Provisioning request submitted successfully."
        Write-Host "Note: OneDrive creation is asynchronous and may take time."
    }
}
catch {
    Write-Error "Could not find user $UserEmail or unable to query Microsoft Graph."
}

Disconnect-SPOService
Disconnect-MgGraph
2>
Open up a powershell window as Admin and go to the directory you have saved your script



3>
Run the script

.\singleconvert.ps1
You'll see the following syntax appear


4>
Paste in the email of the user and press enter


5>
You will be prompted to login with a user that has privileges to work in the 365 tenant.




6>
You will get a subsequent prompt (likely) to enter in your credentials for a user that has 365 admin privileges



When the script is done (about 5 seconds) you'll see this.   


7>
Check your tenant again.  In my experience, if the script is run, and assuming the rest of your licenses are good, it only took a few minutes for the status to change in 365


NOTE:

The script isn't perfect.  It sometimes will error out for now reason.  If you see an error, try running it 2 or 3 more times.



How to find your Tenant ID

You can find your Tenant ID (at time of writing) but going to portal.azure.com, logging in and selecting "Microsoft Entra ID"

It will show you tenantID on the screen.

No comments:

Post a Comment

Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.