| | 0

Working with the OneDrive PowerShell Module

Recently I got some questions on how to work with my PowerShell module for OneDrive. Therefor, 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"

Show files and folders

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

Create new folder in OneDrive

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

Copy files from local to OneDrive

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

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"

Delete file in OneDrive

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