Skip to content

Connect PowerShell to OneDrive


How to connect PowerShell to OneDrive




Get-ODAuthentication -ClientId 162b1a22-8cff-4540-9237-5add19844d46 -RedirectURI




  • Go to
  • Go to app registration
  • Click “new registration”
  • Give it a name

Choose “Accounts in any organizational directory (Any Azure AD directory – Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)”

  • Click register
  • Api permission, add a permission
  • Click “Microsoft Graph”
  • Click “delegated permissions”
  • In search, type “files”
  • Select all under files
  • Click “app permission”
  • Expose an api, add a scope
  • Save and continue
  • Scope name
  • Admins and users
  • Admin consent display name
  • Admin consent description
  • Add Scope
  • Authentication, add a platform, single page application
  • Click configure
  • Scroll down a little and choose “access token”
  • Click save
  • Copy “Application (client) ID”
  • In ISE powershell, run commnad, and replace the clientid with the one you copied

Get-ODAuthentication -ClientId 162b1a22-8cff-4540-9237-5add19844d46 -RedirectURI



  • It will ask you to sign in to get the access token that will be used in PS later.
  • Enter password
  • Click yes to allow app access – you may need to scroll down
  • Powershell result will give you the access token.
  • Copy the access token from the screen to text editor, remove all spaces, Save it in a var in PS
  • $accesstoken = “accesstoken”
  • Go to onedrive to get the path of the folder you want to list all files in it and copy the name of the folder
  • In PS, traverse to the folder on your computer to extract the csv to it
  • Run PS command to list all files under that folder in onedrive and export it to csv file, replace the folder name from onedrive with “folderpathhere” in the command.
  • Get-ODChildItems -AccessToken $accesstoken -Path “/folderpathhere” -SelectProperties * | Export-Csv doneupload.csv -NoTypeInformation -Encoding UTF8
  • So, the command should look like this
  • Get-ODChildItems -AccessToken $accesstoken -Path “/mickey and donald1” -SelectProperties * | Export-Csv doneupload.csv -NoTypeInformation -Encoding UTF8