Marcel
Marcel That's me: Marcel

Working with the OneDrive PowerShell Module

Working with the OneDrive PowerShell Module

Recently I got some questions on how to work with my PowerShell module for OneDrive. Therefore, I put together some examples.

Remember: The OneDrive module is for OneDrive personal and doesn’t work with OneDrive business / Sharepoint.

First: Register an app (authentication) for OneDrive: https://www.sepago.de/blog/onedrive-powershell-module-new-version-with-improved-authentication/

Authenticate to OneDrive


$Authentication=Get-ODAuthentication -ClientID "xxxxxxxxxxxxxxxxxxxxxxx" -AppKey "yyyyyyyyyyyyyyyy" -RedirectURI "http://localhost/login"
$at=$Authentication.access_token

img

Show files and folders

Get-ODChildItems -AccessToken $at -path "/"

img

Create a new folder in OneDrive

New-ODFolder -AccessToken $at -FolderName "Images"

img

Copy files from local to OneDrive

Add-ODItem -AccessToken $at -LocalFile ".\LA-02.jpg" -Path "/Images" 

img Copy file from OneDrive to local disk

Get-ODItem -AccessToken $at -Path "/Images/LA-02.jpg" -LocalPath "D:\Local\downloads"
Get-ODItem -AccessToken $at -Path "/Images/LA-02.jpg" -LocalPath "D:\Local\downloads" -LocalFileName "Copy from OneDrive.jpg"

img

Delete file in OneDrive

Remove-ODItem -AccessToken $at -Path "/Images/LA-02.jpg"

img

First published on: https://www.sepago.de/blog/working-with-the-onedrive-powershell-module/