Powershell onedrive

Powershell onedrive DEFAULT

Pre-provision OneDrive for users in your organization

By default, the first time that a user browses to their OneDrive it's automatically created (provisioned) for them. In some cases, such as the following, you might want your users' OneDrive locations to be ready beforehand, or pre-provisioned:

  • Your organization has a custom process for adding new employees, and you want to create a OneDrive when you add a new employee.

  • Your organization plans to migrate from SharePoint Server on-premises to Microsoft 365.

  • Your organization plans to migrate from another online storage service.

This article describes how to pre-provision OneDrive for your users by using PowerShell.


The user accounts that you're pre-provisioning must be allowed to sign in and must also have a SharePoint license assigned. To provision OneDrive by using this cmdlet, you must be a global or SharePoint administrator and must be assigned a SharePoint license.


If you're pre-provisioning OneDrive for a large number of users, it might take multiple days for the OneDrive locations to be created.

Pre-provision OneDrive for users

  1. If you're pre-provisioning OneDrive for many users, create a list of these users and save it as a file. For example, create a text file named Users.txt that contains:

  2. Download the latest SharePoint Online Management Shell.


    If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall "SharePoint Online Management Shell."

  3. Connect to SharePoint as a global admin or SharePoint admin in Microsoft 365. To learn how, see Getting started with SharePoint Online Management Shell.


    The PowerShell command Request-SPOPersonalSite works only for users who are allowed to sign in. If you've blocked users from signing in, you can allow them to sign in by running the PowerShell command Set-MsolUser using the text file you created in Step 1.

  4. Run the PowerShell command Request-SPOPersonalSite, consuming the text file you previously created in Step 1.

To verify that OneDrive has been created for your users, see Get a list of all user OneDrive URLs in your organization.

Pre-provision OneDrive for all licensed users in your organization

The following code snippet will pre-provision OneDrive in batches of 199.

Related topics

Plan hybrid OneDrive

Sours: https://docs.microsoft.com/en-us/onedrive/pre-provision-accounts

View the list of OneDrive URLs for users in your organization

This article is for global and SharePoint admins in Microsoft 365 who want to confirm the OneDrive URLs for users in their organization.

About OneDrive URLs

The URL for a user's OneDrive is usually in the following format: . For the user principal name (UPN), any special characters such as a period, comma, space, and the at sign ("@") are converted to underscores ("_"). See the following table for examples.

DomainUPNOneDrive URL

Numbers or GUIDs might be appended to the URL if a conflict is detected, so it's always best to confirm a user's OneDrive URL if you need to specify it.


Unless OneDrive accounts are pre-provisioned, the URL isn't created until a user accesses their OneDrive for the first time.

Also, the OneDrive URL will automatically change if the user's UPN changes. For example, if the user changes their name or the domain name changes for a rebranding or business restructuring.

Use the OneDrive usage report to view the list of OneDrive users and URLs

  1. Go to the OneDrive usage report in the Microsoft 365 admin center and sign in as a SharePoint admin, global admin, global reader, or reports reader. (If you see a message that you don't have permission to access the page, you don't have one of these roles in your organization.)

  2. Scroll to the table below the charts.

    Table of URLs at the bottom of the OneDrive usage report

If you see GUIDs in the table instead of URLs and names, go to the Reports setting and clear the box In all reports, display de-identified names for users, groups, and sites.

You can copy individual OneDrive URLs from the URL column. For easier searching and copying, export the table as a .csv file. In the upper left of the table, select Export.

Learn more about the Microsoft OneDrive usage report

Use PowerShell to create a list of all the OneDrive URLs in your organization

The list you create in these steps will be saved to a text file.

  1. Download the latest SharePoint Online Management Shell.


    If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall "SharePoint Online Management Shell."

  2. Save the following text to a PowerShell file. For example, you could save it to a file named OneDriveSites.ps1.

  3. Open the SharePoint Online Management Shell. Navigate to the directory where the script has been saved and run:


    If you get an error message about being unable to run scripts, you might need to change your execution policies. For info, see About Execution Policies.

  4. The script will prompt you for the SharePoint admin center URL. For example, is the Contoso SharePoint admin center URL.

  5. You will then be prompted to sign in. Use a SharePoint admin or global admin account.

After the script successfully completes, a text file is created in the location specified by the $LogFile variable in the script. This file contains a list of all OneDrive URLs in your organization. The following text provides an example of how the list of URLs in this file should be formatted.

Once you have the URL for a user's OneDrive, you can get more info about it by using the Get-SPOSite cmdlet, and change settings by using the Set-SPOSite cmdlet.

Sours: https://docs.microsoft.com/en-us/onedrive/list-onedrive-urls
  1. Minecraft skin skirt
  2. 20g mitsubishi turbo
  3. Windows bible code search pro
  4. 5 star nails

Create folders in OneDrive For Business using PowerShell PnP – What do I need to do?

A few years back, I needed to create folders in OneDrive for Business in preparation for a migration. And as PowerShell PnP (Patterns & Practices) didn’t exist, I used CSOM (Client Side Object Model).
Now that we have SharePoint PowerShell PnP, we can accomplish so much with only a few lines of code, and it’s more “admin-friendly“.

In this blog post, we are going to see the process of creating folders in OneDrive for Business, and also what I call “clean up after yourself” 🙂


Process Overview

There’s a process to follow if you want things to go smoothly.

So here we go:

  1. Pre-provision each OneDrive for Business in order to get the URL (the web address needs to exist if we want to access the OneDrive)
  2. Retrieve each user’s OneDrive for Business URLs (to add second admin in step 3 below)
  3. Add a second Site Collection Admin on each OneDrive for Business (remember only the user is an admin otherwise)
  4. Create the folders on each OneDrive for Business
  5. Remove the second Site Collection Admin from each OneDrive for Business (“clean after yourselffor security reasons!)

⚠️ This process assumes that the users are already licensed for SharePoint Online.


1) Pre-Provision each OneDrive for Business

When you license a user for SharePoint Online, the OneDrive for Business URL is not automatically created. The user needs to access his/her Office 365 account, click on OneDrive, and a few “next, next, next“…
But sometimes for a better user experience, you’d want to pre-provision OneDrive beforehand.

You can use a simple .csv file in your script, or enter the usernames manually when using the New-PnPPersonalSite cmdlet if only a limited number (like below).

#Connect to SPO Connect-PnPOnline -Url https://<TENANT_NAME>-admin.sharepoint.com #Pre-provision the ODFB to create the URLs $myUsers = Import-Csv -Path 'C:\users\$env:USERNAME\Desktop\UsersToPreProv.csv' New-PnPPersonalSite -Email $myUsers

ℹ️ My csv file only contains one header called “UserPrincipalName” (without quotes) with all the users UPN



2) Retrieve each user’s OneDrive for Business URL

Now that the URL has been created, let’s export into a .csv file the URLs we are interested in, by using the same .csv file we used earlier.
To retrieve the URLs, we’ll use the Get-PnPUserProfileProperty cmdlet.

#Import users $myUsers = Import-Csv -Path "C:\users\$env:USERNAME\Desktop\UsersToPreProv.csv" #Retrieve the URLs + export them $ODFBurls = @() foreach ($user in $myUsers) { $ODFBurls += Get-PnPUserProfileProperty -Account $user.UserPrincipalName } $ODFBurls | Select-Object PersonalUrl | Export-Csv -Path "C:\users\$env:USERNAME\desktop\URLs.csv" -NoTypeInformation

The results should look like this:




3) Add a 2nd Site Collection Admin on each OneDrive for Business

First, why do we need to add another Site Collection Admin? Well because by default, only the user is a Site Collection admin.
Which is normal when you think about… It’s their own personal space. So even with a Global Admin account, you’ll get an Access Denied 😉

So in order to create the folders, then we need to add our account.
To that end, we’ll have touse theSet-SPOUser cmdlet (from the SharePoint Online module by Microsoft) on each user’s OneDrive for Business site. The reason for not using the Add-PnPSiteCollectionAdmin from the PnP module is that this command needs to be run in the current context. Meaning we need to be able to connect to that site first, and then add an account.

Therefore, it’s not possible for OneDrive for Business as that’s what we’re trying to achieve: Add our own account.

#Connect to SharePoint Admin Center using the SPO module $creds = Get-Credential Connect-SPOService -Url https://<TENANT_NAME>-admin.sharepoint.com -Credential $creds #Import users $userURLs = Import-Csv -Path "C:\users\$env:USERNAME\Desktop\URLs.csv" #Store 2nd Admin account into a variable $adminAcctToAdd = "[email protected]" #Add 2nd Site Collection admin foreach ($url in $userURLS) { Write-Host "Connecting to: $($url.PersonalUrl) and adding user $($adminAcctToAdd)" -ForegroundColor Green Set-SPOUser -Site $url.PersonalUrl -LoginName $adminAcctToAdd -IsSiteCollectionAdmin $true }

ℹ️ If you have your credentials stored in the Credential Manager, you can remove the , and use



4) Create folders in OneDrive for Business

In this step, you can also have a look at my other post to learn how to create folders, add files, etc…

#Import URLs $userURLs = Import-Csv -Path "C:\users\$env:USERNAME\Desktop\URLs.csv" #Add a folder in each ODFB foreach ($url in $userURLs) { Connect-PnPOnline -Url $url.PersonalUrl Add-PnPFolder -Name "Folder1" -Folder "Documents" }




5) Remove 2nd Site Collection Admin from OneDrive for Business

Now that we have completed our task(s), let’s remove our account for security reasons 😉

Very simple process as we are using the exact same script as in step 3 when adding the account, with the only difference of
If you are still connected to SharePoint with the SPO module, you don’t need to do it again.

#Import users $userURLs = Import-Csv -Path "C:\users\$env:USERNAME\Desktop\URLs.csv" #Store 2nd Admin account into a variable $adminAcctToRemove = "[email protected]" #Remove 2nd Site Collection admin foreach ($url in $userURLs) { Write-Host "Connecting to: $($url.PersonalUrl) and adding user $($adminAcctToRemove)" -ForegroundColor Green Set-SPOUser -Site $url.PersonalUrl -LoginName $adminAcctToRemove -IsSiteCollectionAdmin $false }



Good to know

ℹ️ If you run the following cmdlet, you will get the URLs already available within your tenant:


ℹ️ In the new Office 365 portal, you have the possibility to create a link to access his/her OneDrive for Business if it has been pre-provisioned already.
Click on the user name >> OneDrive tab (when the blade opens) >> click on the link called Create link to files under “Get access to files”.
If the OneDrive is not pre-provisioned, you will see the following:



There you have it! Thanks for reading 😇



Like this:



Sours: https://veronicageek.com/microsoft-365/onedrive-for-business/create-folders-in-onedrive-for-business-using-powershell-pnp-what-do-i-need-to-do/2019/05/
OneDrive installation with powershell

Requirement: Get OneDrive for business usage report using PowerShell

How to Check the OneDrive for Business Usage for a User in Office 365?

OneDrive for Business is Microsoft’s cloud-based storage solution that lets you store and work on files that are personal to you. It’s similar to any other document library in SharePoint with full control granted to you so that you can add, update, and delete files or folders in your OneDrive. To get the storage usage on OneDrive for business for a specific user,

  • Login to Office 365 Admin Centre, Search, and find the user.
  • From the user settings page, expand the OneDrive for business settings menu and under Quota You’ll see the Storage used value!
    onedrive for business usage powershell

PowerShell to Check OneDrive for Business Usage

Here is the PowerShell to check OneDrive for business usage.

#Variables $AdminSiteURL="https://crescent-admin.sharepoint.com" $OneDriveURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com" #Connect to SharePoint Online Admin Center Connect-SPOService -Url $AdminSiteURL # -credential (Get-Credential) #Get All Properties of the OneDrive Site Get-SPOSite $OneDriveURL | Select -Property *

To get OneDrive for business site size using PowerShell, you can use:

Get-SPOSite $OneDriveURL | Select @{Name="Storage Used";Expression={$_.StorageUsageCurrent}}

How about getting OneDrive for Business storage space for all sites? Well, using PowerShell we can create a
quick report to check how much storage does OneDrive for business sites have.

#Variable for SharePoint Online Admin Center URL $AdminSiteURL="https://crescent-admin.sharepoint.com" #Connect to SharePoint Online Admin Center Connect-SPOService -Url $AdminSiteURL -credential (Get-Credential) #Get All OneDrive Sites Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'"

This PowerShell script pulls all OneDrive for Business sites.

onedrive for business usage report using powershell

Export OneDrive for Business sites storage size report to CSV

Let’s pull Onedrive for business usage using powershell and export the result to CSV file.

#Variable for SharePoint Online Admin Center URL $AdminSiteURL="https://crescent-admin.sharepoint.com" $CSVFile = "C:\Temp\OneDrives.csv" #Connect to SharePoint Online Admin Center Connect-SPOService -Url $AdminSiteURL -credential (Get-Credential) #Get All OneDrive Sites usage details and export to CSV Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'" | Select URL, Owner, StorageQuota, StorageUsageCurrent, LastContentModifiedDate | Export-Csv -Path $CSVFile -NoTypeInformation

This PowerShell script retrieves URL, Owner, Storage Quota allocated, Storage Used and Last Updated Date property values of all OneDrive for Business sites and generates report as below:

powershell check onedrive for business usage

This generates a report listing all OneDrive for Business sites in the tenant with the storage allocated and used for each site. Here is another post to get OneDrive storage quota using PowerShell: Get OneDrive for Business Size using PowerShell

Related Posts

Sours: https://www.sharepointdiary.com/2019/08/onedrive-for-business-usage-report-using-powershell.html

Onedrive powershell

Transfer all OneDrive files to another user via PowerShell

OneDrive Transfer Via PowerShell

During the offboarding of an Office 365 user, you may be required to make a copy of their OneDrive files or transfer ownership of the files to someone else. 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 news is, we can do this with PowerShell. The below script makes it relatively easy to copy a user’s entire OneDrive directory into a subfolder in another user’s OneDrive.

The bad news is, there are a few things you’ll need to consider before you use it:

Things to keep in mind

  • This could take a while.
    Each file or folder takes at least a second or two to process. If your departing user has tens of thousands of files, and time is not on your side, you may want to use another method.
  • It uses your connection
    It downloads the files before uploading them to the other user’s OneDrive. If your connection is slow, and you’re moving large files you might want to leave this running on a cloud hosted server.
  • It can’t move files larger than 250MB
    A limitation of this PowerShell module is that it can’t send files larger than 250MB to SharePoint. This script will make a note of these files and export a list of them to c:\temp\largefiles.txt in case you want to move them manually.
  • No Two Factor Authentication
    This script doesn’t work with multifactor authentication on the admin account. You may want to create a temporary admin without MFA for this purpose.


For this script to work, you’ll need to install the following PowerShell Modules:

SharePoint Online Management Shell

The SharePoint Online Management Shell is used to modify the permissions on the users’ OneDrive site collections.

Download and install it here: https://www.microsoft.com/en-au/download/details.aspx?id=35588

SharePoint PnP Powershell Module

The SharePoint PnP Powershell module provides the cmdlets we’ll use to transfer the files and folders between OneDrive accounts.

To install it, open a PowerShell window as an administrator and run the following cmdlet:

Install-Module SharePointPnPPowerShellOnline -Force

MSOnline V1 Powershell Module

You’ll also need the MSOnline V1 PowerShell Module for this script.

To install it, open a PowerShell window as an administrator and run the following cmdlet:

Install-Module MSOnline -Force

How to copy OneDrive files between users via PowerShell


  1. Open Visual Studio Code, or PowerShell ISE and copy and paste the script at the bottom of this article.
  2. Run it by pressing F5
  3. Follow the prompts, entering the following info:
    The username of the departing user. This is the user whose OneDrive we’ll be copying
    The username of the destination user. This is the user that will receive the OneDrive files in a subfolder within their OneDrive
    The username of your Office 365 Admin.Enter Details For OneDrive Transfer
  4. The script will check for files too large to be transferred. If there are any, their details will be logged in C:\temp\largefiles.txtOneDrive Large Files
  5. Wait for the folders and files to be created. Folders are created first, so that the Copy-PnPFile cmdlet has an existing path to place the files.Wait For OneDrive Files To Copy Between Users
  6. Once it’s done, you’ll find the files and folders in the destination users OneDrive under a subfolder called “Departing User” files. Where Departing User is the display name of the user that’s leaving.Files Located In Destination OneDrive

Complete PowerShell script to transfer OneDrive data to another user

$departinguser = Read-Host "Enter departing user's email" $destinationuser = Read-Host "Enter destination user's email" $globaladmin = Read-Host "Enter the username of your Global Admin account" $credentials = Get-Credential -Credential $globaladmin Connect-MsolService -Credential $credentials $InitialDomain = Get-MsolDomain | Where-Object {$_.IsInitial -eq $true} $SharePointAdminURL = "https://$($InitialDomain.Name.Split(".")[0])-admin.sharepoint.com" $departingUserUnderscore = $departinguser -replace "[^a-zA-Z]", "_" $destinationUserUnderscore = $destinationuser -replace "[^a-zA-Z]", "_" $departingOneDriveSite = "https://$($InitialDomain.Name.Split(".")[0])-my.sharepoint.com/personal/$departingUserUnderscore" $destinationOneDriveSite = "https://$($InitialDomain.Name.Split(".")[0])-my.sharepoint.com/personal/$destinationUserUnderscore" Write-Host "`nConnecting to SharePoint Online" -ForegroundColor Blue Connect-SPOService -Url $SharePointAdminURL -Credential $credentials Write-Host "`nAdding $globaladmin as site collection admin on both OneDrive site collections" -ForegroundColor Blue # Set current admin as a Site Collection Admin on both OneDrive Site Collections Set-SPOUser -Site $departingOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $true Set-SPOUser -Site $destinationOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $true Write-Host "`nConnecting to $departinguser's OneDrive via SharePoint Online PNP module" -ForegroundColor Blue Connect-PnPOnline -Url $departingOneDriveSite -Credentials $credentials Write-Host "`nGetting display name of $departinguser" -ForegroundColor Blue # Get name of departing user to create folder name. $departingOwner = Get-PnPSiteCollectionAdmin | Where-Object {$_.loginname -match $departinguser} # If there's an issue retrieving the departing user's display name, set this one. if ($departingOwner -contains $null) { $departingOwner = @{ Title = "Departing User" } } # Define relative folder locations for OneDrive source and destination $departingOneDrivePath = "/personal/$departingUserUnderscore/Documents" $destinationOneDrivePath = "/personal/$destinationUserUnderscore/Documents/$($departingOwner.Title)'s Files" $destinationOneDriveSiteRelativePath = "Documents/$($departingOwner.Title)'s Files" Write-Host "`nGetting all items from $($departingOwner.Title)" -ForegroundColor Blue # Get all items from source OneDrive $items = Get-PnPListItem -List Documents -PageSize 1000 $largeItems = $items | Where-Object {[long]$_.fieldvalues.SMTotalFileStreamSize -ge 261095424 -and $_.FileSystemObjectType -contains "File"} if ($largeItems) { $largeexport = @() foreach ($item in $largeitems) { $largeexport += "$(Get-Date) - Size: $([math]::Round(($item.FieldValues.SMTotalFileStreamSize / 1MB),2)) MB Path: $($item.FieldValues.FileRef)" Write-Host "File too large to copy: $($item.FieldValues.FileRef)" -ForegroundColor DarkYellow } $largeexport | Out-file C:\temp\largefiles.txt -Append Write-Host "A list of files too large to be copied from $($departingOwner.Title) have been exported to C:\temp\LargeFiles.txt" -ForegroundColor Yellow } $rightSizeItems = $items | Where-Object {[long]$_.fieldvalues.SMTotalFileStreamSize -lt 261095424 -or $_.FileSystemObjectType -contains "Folder"} Write-Host "`nConnecting to $destinationuser via SharePoint PNP PowerShell module" -ForegroundColor Blue Connect-PnPOnline -Url $destinationOneDriveSite -Credentials $credentials Write-Host "`nFilter by folders" -ForegroundColor Blue # Filter by Folders to create directory structure $folders = $rightSizeItems | Where-Object {$_.FileSystemObjectType -contains "Folder"} Write-Host "`nCreating Directory Structure" -ForegroundColor Blue foreach ($folder in $folders) { $path = ('{0}{1}' -f $destinationOneDriveSiteRelativePath, $folder.fieldvalues.FileRef).Replace($departingOneDrivePath, '') Write-Host "Creating folder in $path" -ForegroundColor Green $newfolder = Ensure-PnPFolder -SiteRelativePath $path } Write-Host "`nCopying Files" -ForegroundColor Blue $files = $rightSizeItems | Where-Object {$_.FileSystemObjectType -contains "File"} $fileerrors = "" foreach ($file in $files) { $destpath = ("$destinationOneDrivePath$($file.fieldvalues.FileDirRef)").Replace($departingOneDrivePath, "") Write-Host "Copying $($file.fieldvalues.FileLeafRef) to $destpath" -ForegroundColor Green $newfile = Copy-PnPFile -SourceUrl $file.fieldvalues.FileRef -TargetUrl $destpath -OverwriteIfAlreadyExists -Force -ErrorVariable errors -ErrorAction SilentlyContinue $fileerrors += $errors } $fileerrors | Out-File c:\temp\fileerrors.txt # Remove Global Admin from Site Collection Admin role for both users Write-Host "`nRemoving $globaladmin from OneDrive site collections" -ForegroundColor Blue Set-SPOUser -Site $departingOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $false Set-SPOUser -Site $destinationOneDriveSite -LoginName $globaladmin -IsSiteCollectionAdmin $false Write-Host "`nComplete!" -ForegroundColor Green

Was this article helpful?

About The Author

Elliot Munro

Need additional help? Want to be across Microsoft 365 updates and GCITS articles when they're released? Connect with Elliot Munro on LinkedIn here. If you have an Office 365 or Azure issue that you'd like us to take a look at (or have a request for a useful script) send Elliot an email at [email protected]

Related Articles

Sours: https://gcits.com/knowledge-base/transfer-users-onedrive-files-another-user-via-powershell/
OneDrive installation with powershell


  • 25,046
  • 5,417
  • View full stats
  • 11/10/2018



Provides function to access OneDrive personal and 4 business with PowerShell. You can list directories, get metadata of files and folder, create folders, delete folders and file and for sure: Upload and download files. This module uses an authentication describes here: https://github.com/MarcelMeurer/PowerShellGallery-OneDrive At this time there are some functions mis

Provides function to access OneDrive personal and 4 business with PowerShell. You can list directories, get metadata of files and folder, create folders, delete folders and file and for sure: Upload and download files. This module uses an authentication describes here: https://github.com/MarcelMeurer/PowerShellGallery-OneDrive At this time there are some functions missing, like rename files. Please write me a mail if you find some errors or if you have a request.

Show more

Installation Options

Copy and Paste the following command to install this package using PowerShellGet More Info

Install-Module -Name OneDrive -RequiredVersion 2.1.1

You can deploy this package directly to Azure Automation. Note that deploying packages with dependencies will deploy all the dependencies to Azure Automation. Learn More

Manually download the .nupkg file to your system's default download location. Note that the file won't be unpacked, and won't include any dependencies. Learn More


[email protected]


(c) 2016 [email protected]

Package Details


Version History

VersionDownloadsLast updated
2.2.7 5,417 8/11/2020
2.2.6 99 8/6/2020
2.2.5 2,006 4/15/2020
2.2.4 769 3/9/2020
2.2.3 1,771 11/25/2019
2.2.2 205 11/14/2019
2.2.1 1,910 7/2/2019
2.2 332 6/21/2019
2.1.1 (current version) 5,297 11/10/2018
2.1.0 14 11/10/2018
2.0.0 197 10/27/2018
1.1.4 165 10/23/2018
1.1.3 3,883 10/8/2017
1.1.2 18 10/8/2017
1.1.1 17 10/7/2017
1.1.0 28 10/6/2017
1.0.3 1,854 11/9/2016
1.0.2 28 11/8/2016
0.9.2 1,016 2/21/2016
0.9.1 20 2/19/2016
Show less
Sours: https://www.powershellgallery.com/packages/OneDrive/2.1.1

Similar news:

OneDrive PowerShell Module – Added support for OneDrive for Business

More than two years ago, I created my PowerShell module to access OneDrive. This module can be installed with a one-liner from https://www.powershellgallery.com/packages/OneDrive

Again, I was asked to support OneDrive for Business and finally, I’m ready: From version 2.0.0 OneDrive for Business is supported.


I provide the complete documentation on GitHub, where I will maintain it: https://github.com/MarcelMeurer/PowerShellGallery-OneDrive


Here is the summary of version 2.0.0:


The OneDrive PowerShell module is available via PowerShellGallery.com. 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 (2.0.0 and higher in PowerShellGallery.com) supports:

  •  OneDrive personal
  •  OneDrive for Business


Open PowerShell and

Install-Module -Name OneDrive -Scope CurrentUser -force

You can update the module to a newer version with the same command (-force). If you don’t use PowerShellGet currently, go to the Gallery on https://www.powershellgallery.com/packages/OneDrive and click “Get Started”.

Check your installation with

Get-Help -Name OneDrive


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

OneDrive Personal

Read this on my blog: https://www.sepago.de/blog/onedrive-powershell-module-new-version-with-improved-authentication/

$Auth=Get-ODAuthentication -ClientID 5dd40b03-0ead-451b-b5e3-f704550e8cca -AppKey xqacs8K92MuCJKgciRHQ1Cf -RedirectURI http://localhost/login

OneDrive for Business

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

$Auth=Get-ODAuthentication -ClientId "2831fc52-e1b8-4493-9f3a-a3dad74b2081" -AppKey "TqoSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX="&nbsp; -RedirectURI "http://sepago.de/1Drive4Business" -ResourceId "https://sepagogmbh-my.sharepoint.com/"

Renew the authentication with a refresh token

An access token is 1 hour valid. You can get a new access token with the refresh token provided by the last authentication. This is necessary if you are creating a script that will work for a long time without further user input. Renew your access token automatically in the program code.

$Auth=Get-ODAuthentication -ClientId 2831fc52-e1b8-4493-9f3a-a3dad74b2081 -AppKey "TqoSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=" -RedirectURI "http://sepago.de/1Drive4Business" -ResourceId "https://sepagogmbh-my.sharepoint.com/" -RefreshToken $LastAuth.refresh_token
  • Where $LastAuth is your last authentication result (containing the refresh token)
  • For OneDrive personal leave the ResourceId empty (-ResourceId “”)

Working with files and folders

Get an authentication code from above and store it in $Auth

List files and folders

Get-ODChildItems -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -path "/"

List files and folders

Remove-ODItem -AccessToken $Auth.access_token -ResourceId “https://sepagogmbh-my.sharepoint.com/” -path “/Upload”

Creating a folder

New-ODFolder -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -path "/" -FolderName "Upload"

Upload local files to OneDrive

Add-ODItem -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -LocalFile "D:\DEV\PowerShell\PowerShellGallery-OneDrive\Test\Uploads\IoT Workshop.pptx" -Path "/Upload"

List OneDrive drives

Get-ODDrives -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/"

Downloading some files

Get-ODItem -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -Path "/Upload/Doings.txt" -LocalPath "D:\DEV\PowerShell\PowerShellGallery-OneDrive\Test\Downloads" Get-ODItem -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -Path "/Upload/Doings.txt" -LocalPath "D:\DEV\PowerShell\PowerShellGallery-OneDrive\Test\Downloads" -LocalFileName "Copy from OneDrive.Doings.txt"

Delete a file in OneDrive

Remove-ODItem -AccessToken $Auth.access_token -ResourceId "https://sepagogmbh-my.sharepoint.com/" -Path "/Upload/Doings.txt"


Sours: https://www.sepago.de/blog/onedrive-powershell-module-added-support-for-onedrive-for-business/

517 518 519 520 521