How to connect PowerShell to SharePoint Online

Prominent among them is the one dedicated to SharePoint.

PowerShell is a powerful mass automation tool designed to help a company’s IT department manipulate and coordinate the underlying operations of an operating system, application, or Web page. How?

With the famous cmdlets and their preconfigured modules.

Prominent among them is the one dedicated to SharePoint.

Let’s find out all the details together.

What you will find in this article

Steps for admin account with multi-factor authentication

PowerShell: what it is and what is it for

Automation and scripting: that’s how we could sum up, in a nutshell, what PowerShell is.

This platform was created by Microsoft to help IT teams automate processes inherent in a company’s IT resources using custom scripts and commands.

Thus, it is a tool directed at experienced programming users who do not want to waste time creating automation manually, one by one, and always starting from scratch.

Instead, they want to make tasks such as installing apps, configuring servers, or managing SharePoint site collections in bulk automatic.

If you also share this goal, or if you are simply curious about what PowerShell can do for your business, you are in the article.

See intranet.ai in action

A ready-to-use intranet on SharePoint Online, live in days. Book a free demo with our team.

Book a demo

What are the main features of PowerShell

As anticipated in the last chapter, PowerShell constitutes both a scripting language and a platform intended for the automation of operating systems, especially, but also of applications and Web pages.

Regarding operating systems, it should be noted that a major advantage of PowerShell is that it can adapt to major platforms (Windows, Linux, and macOS) without any problems.

To achieve its goal, it leverages the .NET framework, which allows it to provide users with several ways in which they can create their automations. These include:

  • Cmdlet.

  • Scripts.

  • Executable files.

  • Standard .NET classes.

A brief parenthesis must be opened for the first ones.

Indeed, cmdlets (pronounced “command-lets”) represent the most characteristic elements of PowerShell, and the most commonly used by users.

Specifically, they are lightweight and specialized commands, since each of them adheres to a simple (Verb-Substantive) and standardized syntax that refers to a single operation. Some examples might be “Get-Location,” “Move-Item,” and “Remove-Item.”

However, cmdlets can be combined to create custom scripts according to the logic of “pipelining,” the function that allows the output of one command to be transformed into the input of another and that, in PowerShell, lets objects flow from one cmdlet to the next.

The result of pipelining (indicated by the ”|” symbol) is a chain reaction that allows users to achieve more sophisticated solutions and process more complex data.

If you then think that PowerShell has over 200 cmdlets, it is evident how these chains can develop in size and customization, also relying on the use of conditional expressions, switches (used to replace a long succession of if/then/else conditions), loops and variables.

In addition, although cmdlets are rather self-explanatory, as we have seen, these come with their documentation, which you can access directly within the platform.

Or, you can use the “Get-Help” command, followed by “online,” to retrieve Web articles that deal with the command or function you are looking for.

In this way, it will be easier for less experienced users to learn the different components of the system and how to use them for their automations.

But that is not all.

There are two other major aspects that we still need to explore to complete our overview.

The first concerns the possibility of using PowerShell remotely.

In fact, users can initiate commands and scripts from remote computers by leveraging the WS-Management protocol or Windows Management Instrumentation.

Without going into too much detail, just know that WS-Management is the protocol developed by the DMTF (Distributed Management Task Force), of which Microsoft is a part, to be able to manage and monitor the resources of a network regardless of the operating system being used.

Windows Management Instrumentation, on the other hand, provides users with a unified representation of a system’s resources, thus enabling them to manipulate them remotely.

The second aspect to be emphasized concerns modularity, that is, the ability to organize cmdlets with related functionality into modules.

In addition, of course, to those created by the user, PowerShell provides 4 types that are already configured. Let’s talk about the modules:

  • Script.

Modules mainly used to import, export, and manage functions.

  • Binaries.

The modules are manipulated to create cmdlets with more powerful functionality than can be obtained from the normal scripts offered by the platform.

  • Manifesto.

Particular modules, which are characterized by being made up of text files, used to describe the components of a module.

Specifically, they define its cmdlets, functions, requirements and dependencies, thus helping users to develop and deploy different modules more easily and quickly.

  • Dynamics.

Modules that are set up at the request of a script.

Because they fulfill a momentary need, they are generally not stored permanently within the platform.

In addition, you can download and install even more modules, which are also preconfigured but are not present in PowerShell.

These include those related to SharePoint site collections, their user groups, and security settings.

Since the topic of our next chapter concerns the relationship between PowerShell and a SharePoint Online tenant, the module we are interested in is precisely the one dedicated to the cloud version of SharePoint. Its name is “Microsoft.SharePoint.Online.Management.”

How to connect a SharePoint Online tenantto PowerShell

Before we look together at the steps to follow to connect PowerShell to one of your SharePoint Online tenants, we need to do a little introduction.

PowerShell applies to any version of SharePoint, allowing users to manage platform settings at the organization and site collection level.

However, as anticipated, you need to download and install the specific module for the type of tenant you want to connect, depending on whether it is on-prem or cloud.

In the former case, the module you need is the one called “Microsoft.SharePoint.Management”; in the latter case, which is then the one we will explore in this chapter, the module you need to equip yourself with is called “Microsoft.SharePoint.Online.Management.”

Although the cmdlets and features that the two modules contain distinguish them from each other, it is possible to find commonalities.

For example, there are always commands that specialize in creating a new collection of sites, defining their title, URL, owner, storage quota, and user groups with related permissions.

In addition, you can find cmdlets that allow you to get detailed reports and statistics regarding the usage and performance of the different sites that make up a collection.

Having said that, let us now turn to the core of our discussion and take the case that you want to use PowerShell to batch manage the operations behind one of your SharePoint Online tenants.

If you have not yet installed the relevant module, the fastest way to do this is to log in as admin to the PowerShell Gallery and run the “Install-Module-Microsoft.SharePoint.Online.Management” cmdlet.

Once that is done, you move on to the connection with the tenant.

The path branches in two parallel directions here, depending on whether your admin account has multi-factor authentication (MFA) or not.

Let’s look at both cases.

1) Steps for admin account with multi-factor authentication

In short, here is how you need to proceed:

  • Access the PowerShell Gallery.

  • Run the “Connect-SPOService-URL(…)” command, specifying the address of your tenant.

  • Enter your Microsoft credentials in the window that will open.

  • Approve the login request, satisfying the authentication requirements.

And that’s it.

Now that the tenant is connected to PowerShell, you can begin to serially manage and manipulate the activities that form its basis.

You will soon see that your IT team no longer has to waste hours or entire days configuring your company’s sites.

2) Steps for admin account without multi-factor authentication

In this case, the process becomes significantly less demanding.

Here is what you need to do:

  • Access the PowerShell Gallery.

  • Run the “Connect-SPOService-URL(…)-Credential(…)” command, specifying your tenant’s address and entering your UPN, which is the e-mail address that indicates both your username and domain.

  • Enter your account password.

Once again, you are done.

To explore this topic further, we recommend reading our article on workflows for SharePoint Online.

Need a hand managing your SharePoint sites?

We’ve got more than 100 on deck to support your company in:

  • Distributing the right permissions to users

  • Ensuring the security of shared information

  • Improving document and resource management

  • Developing custom web parts and branded graphics

Contact us

Article FAQ

How do I Connect to SharePoint online from PowerShell?

To connect to SharePoint Online from PowerShell, you can use the Connect-SPOService cmdlet. This cmdlet establishes a connection to your SharePoint Online environment.

Could not Connect to SharePoint Online using PowerShell?

If you encounter issues connecting to SharePoint Online using PowerShell, ensure that you have the necessary permissions and that your account credentials are correct. Additionally, verify your internet connection and firewall settings.

What is the Connect online PowerShell command?

The Connect-SPOService cmdlet is the PowerShell command used to connect to SharePoint Online. It requires specifying the SharePoint Online admin center URL and providing valid credentials to authenticate.

Can you use PowerShell for SharePoint online?

Yes, PowerShell is a powerful tool for managing SharePoint Online. It allows you to automate various tasks, such as site provisioning, user management, and content management, making administration more efficient and scalable.

What is intranet.ai?

intranet.ai is the ready-to-use corporate intranet designed to cut implementation costs and time, and create a collaborative digital work environment.

  • From €3,950/year for a complete intranet
  • 80+ applications including advanced search, DMS, org chart, and push notifications
  • Integrated with SharePoint Online and Microsoft 365
intranet.ai su desktop, tablet e smartphone

The complete SharePoint intranet integrated with Microsoft 365, starting from 3,950 €/year.

  • 80+ apps for communication, training, and knowledge sharing
  • Compatible with Microsoft 365 and Microsoft Viva
  • Operational within 24 hours from purchase, with 5 days of consulting