OneDrive PowerShell Module - New Version with Improved Authentication

Marcel Meurer's picture

A few months ago, I wrote a PowerShell module to access OneDrive. I got a lot of feedback from the community – thanks for that.

This week I published a newer version to including new features and bugfixes. These are the main improvements:

Bug fixes:

  • Filename and paths containing special characters like ‘=’, ‘$’, etc. are now handled correctly
  • Enumeration of folders with a file count >200 is now working 


  • Get-ODAuthentication now supports a “code” based-authentication including refresh of the authentication with a refresh token. This allows an unattended run of long running scripts.

How to log on to OneDrive using a code based authentication?

Hint: There is also a video on youtube showing this example:

Register your app/script for OneDrive

First, register your app/script at the Application Registration Portal:

  • Go to: and login with your Microsoft Account (MSA)
  • “Add an app” in the category “converged applications”:
  • Enter a name and press “create”
  • Press “Generate New Password“ and save the password (app key) 
  • Also save the “Application id”
  • Press “Add Platforms” and select “Web” 
  • Check “Allow implicit Flow” and enter a “Redirect URL”. This is not a real URL. Choose a localhost address and note it. In my case I chose: http://localhost/login  
  • Press “Save” 

Now you have all necessary data for your app / script:

  • Client Id: 5dd40b03-0ead-451b-b5e3-f704550e8cca
  • AppKey: xqacs8K92MuCJKgciRHQ1Cf
  • RedirectURI: http://localhost/login

Get an authentication token

To get an authentication token use:

Get-ODAuthentication -ClientID 5dd40b03-0ead-451b-b5e3-f704550e8cca -AppKey xqacs8K92MuCJKgciRHQ1Cf -RedirectURI http://localhost/login


Hint: Use “-AutoAccept” to avoid the confirmation windows

Test the authentication token

Save the authentication token to an object:

$Auth= Get-ODAuthentication -ClientID 5dd40b03-0ead-451b-b5e3-f704550e8cca -AppKey xqacs8K92MuCJKgciRHQ1Cf -RedirectURI http://localhost/login

List files in a OneDrive-folder:

Get-ODChildItems -AccessToken $Auth.access_token -Path "/BACKUP Azure Global Bootcamp"


Renew the authentication token

An authentication token is valid for an hour. You can get a new “code” based token with the “refresh_token” from the login before:

$Auth= Get-ODAuthentication -ClientID 5dd40b03-0ead-451b-b5e3-f704550e8cca -AppKey xqacs8K92MuCJKgciRHQ1Cf -RedirectURI http://localhost/login -RefreshToken $Auth.refresh_token


Install the new version of OneDrive from

If you have the module PowerShellGet to access PowerShellGallery already installed, you can easily download this module with a single command (“-force” updates the module to the newest version):

Install-Module -Name OneDrive -Scope CurrentUser -force

You can update the module to a newer version with the same command (add -force). If you don’t use PowerShellGet currently, go to the Gallery on and click on “Get Started”.

If you have any questions or suggestions, write me an email or get in touch with me via 

FileSize Supported
Hi Marcel! I downloaded the latest version of the OneDrive Module for PowerShell and its working fine!! (I followed the steps for command line from another of your posts). But when I try to upload files that are bigger than 80MB, the process returns -1 code. Is there any limitation for file size or upload quota? I have a regular OneDrive account and I have 4GB free on it. I need to upload a file up to 3GB. Help me please, thanks!
Marcel Meurer's picture
Re: FileSize Supported
Hello. Unfortunatly I hadn't implemented the "big file size" method in this modul now. So you have some limits. My upload stops after 300 MByte. I plane "big file type" support for the next version. Marcel
Add new comment
By submitting this form, you accept the Mollom privacy policy.