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

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

img

Show files and folders

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

img

Create a new folder in OneDrive

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

img

Copy files from local to OneDrive

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

img Copy file from OneDrive to local disk

1
2
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

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

img

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