Academy Microsoft 365 atWork Blog

Connect to OneDrive in Microsoft 365 using PowerShell

⭐ PARTNER OF THE BLOG
Microsoft 365 atWork partners with AFI.AI, the developer of modern data protection platform built from the ground up to deliver a fully-fidelity backup for MICROSOFT 365 and GOOGLE WORKSPACE.

Start to work with PowerShell with Microsoft OneDrive.

Connect to Microsoft OneDrive in Office 365 using Microsoft PowerShell on your Windows PC.

PowerShell gives you the possibility to manage Microsoft OneDrive automated and programmatical way. OneDrive is the perfect solution to manage personal data and improves collaboration with other users. PowerShell allows you to automate a lot of activities around these features.

Do the first step and learn how to connect to Microsoft OneDrive PowerShell from Windows 10/11.

Connect to OneDrive in Microsoft 365 using PowerShell

PARTNER OF THE BLOG

Academy Microsoft 365 atWork partners with AFI.AI, the developer of a modern data protection platform built from the ground up to deliver a full-fidelity backup for MICROSOFT 365 and GOOGLE WORKSPACE.

Edit Template

🎯M365 & COPILOT WEEKLY DIGEST

Are you tired of missing out on the latest news, important announcements, insightful articles, and engaging videos? 

I’ve got the perfect solution for you!

Join my weekly newsletter where we gather the most crucial updates and deliver them straight to your inbox or LinkedIn feed, based on your preference.

SUBSCRIBE TO CHAMPIONS NEWSLETTER 

I respect your . Unsubscribe at any time.

How to connect to Microsoft OneDrive using PowerShell

Connecting to the Microsoft OneDrive using PowerShell is based on using a SharePoint management shell. If you would like to improvement in the area of automation and management of OneDrive for Business you will need to use SharePoint PowerShell.

Before you will connect to OneDrive in Office 365 remember to install the SharePoiny PowerShell module first.

Install the SharePoint and OneDrive PowerShell module

In the first step remember to install the Microsoft OneDrive and SharePoint Online PowerShell module on your Windows PC.

Here is the step-by-step instruction on how to install the OneDrive PowerShell module.

Connect to Microsoft OneDrive PowerShell

SharePoint Online PowerShell will allow you to connect to Microsoft OneDrive using PowerShell.

To connect to SharePointPowerShell prepare your login and SharePoint admin site address:

Connect-SPOService -Url https://m365aw-admin.sharepoint.com  -credential szymon@office365atwork.com

You will be asked for your password in the authentication window.

Connect to OneDrive in Microsoft 365 using PowerShell
PowerShell Authentication window

After pasting the password you will be connected to the PowerShell shell and start to work on Microsoft OneDrive using cmdlets.

Connect to Microsoft OneDrive PowerShell with MFA

If your account has Multi-Factor Authentication turned on, you can use SharePoint Online and connect to Microsoft OneDrive using PowerShell but you will need to use different command.

To connect to OneDrive PowerShell with MFA prepare your SharePointadmin site address. You should not use -credential parameter.

Connect-SPOService -Url https://m365aw-admin.sharepoint.com

You will be asked to authenticate in the standard Microsoft 365 login window.

Connect to OneDrive in Microsoft 365 using PowerShell
PowerShell MFA Authentication

After you will paste your email address you should choose Work or school account.

Connect to OneDrive in Microsoft 365 using PowerShell
Select proper Microsoft 365 profile

In this case, after you will use your password you will need to authenticate using MFA.

Connect to OneDrive in Microsoft 365 using PowerShell
Use MFA to authenticate

After the authentication process with MFA, you will be connected to the PowerShell shell and start to work on Microsoft OneDrive using cmdlets.

First steps with Office 365 PowerShell

Connect to OneDrive in Microsoft 365 using PowerShell

Resolve problems with connecting to SharePoint PowerShell

Errors you can meet during the PowerShell connection to Microsoft OneDrive:

  • Connect-SPOService : The sign-in name or password does not match one in the Microsoft account system.
Connect to OneDrive in Microsoft 365 using PowerShell
PowerShell error #1

You did use not the correct password or you are trying to connect using an account with MFA and -credential parameter. Remove the -credential parameter and double-check your password.

  • Connect-SPOService : Current site is not a tenant administration site.
Connect to OneDrive in Microsoft 365 using PowerShell
Save edited file to PDF format

You need to connect to the admin site. The address of the OneDrive admin site will be something like this: https://name-admin.OneDrive.com

Perfect! You have learned how to connect the OneDrive app using PowerShell in Windows.  Now is the time to get a better understanding of Microsoft 365 apps. Learn how to use Power Automate flowshow to deploy and use Viva Connections and how to use OneDrive.

Do you want to learn even more?
I prepared more articles that could help you better understand Power AutomateOneDriveMicrosoft Teams and OneDrive.

Contact with Microsoft MVP

Contact and book a 30-minute call with a Microsoft MVP.

Name
Use your organization email.
How can I help you?

Do you need help?

Contact and book a free consultation call with a Microsoft MVP. During a meeting, I will do my best to share my advice to help with your needs and challenges. 

Connect to OneDrive in Microsoft 365 using PowerShell
Edit Template

Conclusion

Learn how to connect to Microsoft OneDrive using PowerShell in Windows 10/11. Use PowerShell Management Shell to automate the management of Microsoft OneDrive.

Interesting articles for you

Edit Template
Edit Template
Edit Template

1 thought on “Connect to OneDrive in Microsoft 365 using PowerShell”

  1. Is it possible to decide which folders to sync at install of the client? We have certain documents/folders which we want to have locally available and up2date on any notebook we give to our employees.

Leave a Comment

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

Scroll to Top