I have got a service account (Windows AD Data Mgmt) from the company admin so that I can do the following using PowerShell:

  1. Login(Connent-PnPOnline) to a SharePoint site.
  2. Download a file and process it further.

I can login to that SharePoint site using my personal account through PowerShell. Now I want to use the service account instead. Do I have to generate a key for it and if yes, how to do that?

My personal account is registered to that private group which has the SharePoint site. And This is why I can connect it.

Some hint is requested.

2 Answers 2


You do not need to generate a key. When using the PnP cmdlets, you need to verify that the "service account" (note there is no concept of a service account in Azure AD/Office 365) has Owner rights to the site (you can do with less, but I'm assuming what you want to do requires it).

Once you've granted the appropriate rights, you should be able to log in with that account.

  • The account can have MFA enabled. You do need to use the -UseWebLogin switch with Connect-PnPOnline, though.
  • If you're using the SPO cmdlets, the account can have MFA enabled but it needs the SharePoint Online admin role.

You may also want to look into using Power Automate with the Microsoft Data Gateway. This can connect back to on-premises services such as a file server, allowing you to copy the file from SharePoint Online back down for further processing. The account(s) that use this particular flow would require Flow P1 liceses.


We should be able to connect to SharePoint online using the service account(by the way there is no concept of SA in SharePoint online) however,if your local AD is synced with Azure AD, still we can use that local service account in SharePoint online and that account can be used while connecting to SharePoint online using PnP PowerShell or SharePoint online PowerShell and this is exactly the way we connect to the SharePoint online using our own account(normal account).

Sample connection to SharePoint online using PnP:

Connect-PnPOnline –Url https://[tenant]-admin.sharepoint.com/ -UseWebLogin;

Other various examples of Connect-PnPOnline in SharePoint online:


Sometimes with the MFA enabled account we may get error, then we can try the below command:

Connect-PnPOnline -ClearTokenCache -SPOManagementShell -Url

Other MFA with PnP SharePoint connection related issues and their solution:


  • The account should have SharePoint online administrator role in office 365(SharePoint admin center)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.