Powershell download file from onedrive

Powershell download file from onedrive

powershell download file from onedrive

OneDrive Files On Demand is a feature which sets OneDrive to only download files to a local device when a file is clicked on You can enable this option manually on each device or choose to deploy a PowerShell script using InTune or other. This can be a laborious process, requiring you to log into the departing users OneDrive and downloading, transferring or sharing their data manually. The good. As part of our off-boarding process we back up the users OneDrive files manually to our file server. Has anyone had any luck with automating this . powershell download file from onedrive

Powershell download file from onedrive - have

MarcelMeurer / PowerShellGallery-OneDrive

The OneDrive PowerShell module is available via rushbrookrathbone.co.uk If you want to support and work with me feel free to make changes cloning this repo, change and send me and a pull request.

This OneDrive version ( and higher in rushbrookrathbone.co.uk) supports:

What's new

Version

  • Change: A endpoint change from Microsoft regarding OneDrive personnel is adapted to avoid the error: "AADSTS The provided value for the input parameter 'scope' is not valid. The scope '' is not configured for this tenant" for a refresh token

Version

  • Change: A endpoint change from Microsoft regarding OneDrive personnel is adapted to avoid the error: "AADSTS The provided value for the input parameter 'scope' is not valid. The scope '' is not configured for this tenant"

Version

  • Bugfix: Cannot access a path on a remote/shared drive

Version

  • Upload support for larger files: Add-ODItemLarge Typically files larger then 10 MBytes. Uploading this files is not stable with the standard upload process used by Add-ODItem. Thanks to Benke Tamás (funkeninduktor@rushbrookrathbone.co.uk) for sharing this function

Version

  • Downloaded files keeping their time stamps from know Bevor: A downloaded file get the current time as time stamp (created at)

Installation

Open PowerShell and

Install-Module-Name OneDrive -Scope CurrentUser -force

You can update the module to a newer version with the same command (-force). After that you have to restart your PowerShell session. If you don’t use PowerShellGet currently, go to the Gallery on rushbrookrathbone.co.uk and click "Get Started".

Check your installation with

Authentication

Before you start using the OneDrive module you have register your script/application. This differs depending on the OneDrive version to be used.

OneDrive Personal

Read this on my blog: rushbrookrathbone.co.uk

  • Go to: rushbrookrathbone.co.uk and login with your Microsoft Account (MSA) and "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: 5dd40beadb-b5e3-fe8cca
    • AppKey: xqacs8K92MuCJKgciRHQ1Cf
    • RedirectURI: http://localhost/login
  • To get an authentication token use:

    $Auth=Get-ODAuthentication-ClientID 5dd40beadb-b5e3-fe8cca -AppKey "xqacs8K92MuCJKgciRHQ1Cf"-RedirectURI http://localhost/login

Hint: If you create the application in the Azure Portal, make sure to edit the manifest. Change the following values:

"signInAudience": "AzureADandPersonalMicrosoftAccount",

"tags": [

​ "supportsConvergence:true",

​ "availableToOtherTenants:true",

​ "accessTokenVersion:1",

​ "appModelVersion:2"

],

"tokenEncryptionKeyId": null,

"verifiedPublisher": {

​ "displayName": null,

​ "verifiedPublisherId": null,

​ "addedDateTime": null

}

OneDrive for Business

To use OneDrive for business you have to register your script/app to in Azure Active Directory

  • Add an application in Azure Active Directory inside the Azure portal: rushbrookrathbone.co.uk#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps

  • Chose "New registration"

  • Give your application a name and configure the redirect URI. The sign-on URL has to be a valid URL but doesn't have to exist. E.g.: http://localhost/1Drive4Business (make later sure that this url is in the reply url list of your application)

  • Click "Register" to create the Azure application.

  • Next go to "Authentication" and enable "ID tokens" - Save the change

  • Click on API permissions and add the following permissions:

  • Azure Active Directory Graph - Delegated permission - rushbrookrathbone.co.uk

    • SharePoint - Delegated permission - MyFilesRead
    • SharePoint - Delegated permission - MyFilesWrite

  • Generate a secrete key for this application and save it for later use. Also save the application Id

  • You should now have the following parameter:

  • Additionally you need the resource URL for OneDrive for Business. Normally: rushbrookrathbone.co.uk In our company this is the URL "rushbrookrathbone.co.uk" (the last one / is important).

  • To get an authentication token use:

    $Auth=Get-ODAuthentication-ClientId "fce1bf3a-a3dad74b"-AppKey "TqoSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX="-RedirectURI "rushbrookrathbone.co.uk
Источник: [rushbrookrathbone.co.uk]

Powershell download file from onedrive

1 thoughts to “Powershell download file from onedrive”

Leave a Reply

Your email address will not be published. Required fields are marked *