Article IT systems and administration
Robert Szarras | 2023-12-04

PowerShell in SharePoint Online

Currently, servers are a fundamental part of the IT infrastructure in most enterprises and organizations. The reliability and availability of data, applications, and the machines they host play a key role in everyday business operations. Unpredictable failures of this infrastructure can cause disruptions in the smooth operation of the environment and other undesirable consequences, including financial and reputational damage. The most common...

SharePoint Online, part of Microsoft 365 for business, is a powerful tool for collaboration and information sharing within organizations. To optimize management and customize the SharePoint Online environment to individual needs, administrators often use PowerShell. This article will discuss basic PowerShell commands for SharePoint Online and show how they can be used to automate administration and effectively manage resources.

Installing the SharePoint Online PowerShell Module

To get started with PowerShell in the context of SharePoint Online, you must first install the appropriate module and make sure you have SharePoint Administrator or Global Administrator privileges in Microsoft 365. You can install the SharePoint Online module using the following command:

# Module installation SharePointOnline Install-Module -Name Microsoft.Online.SharePoint.PowerShell

After installing the module, you need to connect to SharePoint Online:

# Connection to SharePointOnline Connect-SPOService -Url https://yourtenant-admin.sharepoint.com

When connecting to SharePoint Online, be sure to enter the correct URL, including -admin after your tenant's name. You can obtain your tenant's address by logging into Office365 and going to the SharePoint admin center tab. You'll find the URL in the search bar; that's the name you're looking for.

Basic PowerShell Commands for SharePoint Online

Site Management

SharePoint Online is a dynamic platform built on a site structure. These are virtual workspaces tailored to the needs of projects, groups of people, or departments within a company. Sites are a key element, facilitating collaboration, document storage, and information organization. In practice, this means that a team can use a site to effectively collaborate on a project, share files, and schedule tasks. Importantly, sites are flexible, allowing them to be tailored to specific needs, whether for a team or a specific department within the company. They provide a convenient place to streamline the organization and management of various aspects of a company's operations.

Below are the basic commands for site management:

 

# Get a list of all sites Get-SPOSite # Select one site from the list Get-SPOSite -Identity https://yourtenant.sharepoint.com/sites/sitename # List all site parameters Get-SPOSite -Identity https://yourtenant.sharepoint.com/sites/sitename | FL

Get-SPOSite allows you to obtain general information about websites, such as their name, URL, owner, as well as information about usage and accessibility.

Key Parameters:

  • Identity: Allows you to specify the site(s) for which you want information.
  • Detailed: Provides more detailed information about sites, such as current resource usage, average resource usage, compatibility level, etc.
  • Filter: Allows you to filter sites based on specific criteria.
  • Limit: Limits the number of sites that will be returned.
  • IncludePersonalSite: Allows you to include personal sites in the results.
  • IncludeDetailLog: Allows you to include detailed logs.

More information on using the Get-SPOSite function can be found here: https://learn.microsoft.com/en-us/powershell/module/sharepoint-online/get-sposite?view=sharepoint-ps

 

# Create a new site New-SPOSite -Title "New Site" -Url https://yourtenant.sharepoint.com/sites/nowaWitryna -Owner user@yourtenant.com -StorageQuota 1024 -Template STS#0

Parameters:

  • Title: Specifies the title for the new site.
  • Url: Specifies the URL for the new site.
  • Owner: Specifies the site owner, the user who will have full permissions to manage the site.
  • StorageQuota: Specifies the disk space limit available for the site in megabytes.
  • Template: Specifies the template from which the site will be created. Example templates include STS#0 (team template), STS#1 (blog template), and so on.

 

# Remove Site Remove-SPOSite -Identity https://yourtenant.sharepoint.com/sites/sitename

 

The Remove-SPOSite command can be useful when you want to remove a website from your tenant. If you accidentally deleted your website and would like to recover it, I have good news for you. Websites are not permanently deleted; they are first moved to the trash bin, where they remain for a maximum of 93 days. After that, the website will be permanently deleted.

 

# List deleted sites Get-SPODeletedSite

This command will tell you what websites are currently in the trash.

 

# Restore deleted site Restore-SPODeletedSite -Identity https://yourtenant.sharepoint.com/sites/nazwaWetryny

If you already know what site you want to restore, use the Restore-SPOSiteeDeletedSite command along with its full name.

Group and User Management

In a SharePoint Online environment, controlling site access by groups and users is crucial. Commands related to managing this access play a key role in platform administration. They allow administrators to effectively assign permissions, create workgroups, and ensure that appropriate users have access to specific resources on SharePoint Online sites. Here are some commands that can help in this regard:

 

# Get the list of groups with permissions to the site Get-SPOSiteGroup -Site https://yourtenant.sharepoint.com/sites/sitename

It allows you to obtain information about which groups and with what permissions have access to the website.

 

# Permission Change: Grant Full Control permissions to the Contoso group on the site Set-SPOSiteGroup -Site https://yourtenant.sharepoint.com/sites/sitename -Identity "Contoso" -PermissionLevelsToAdd "Full Control" # Permission Change: Remove Full Control permissions from the Contoso group on the site Set-SPOSiteGroup -Site https://yourtenant.sharepoint.com/sites/sitename -Identity "Contoso" -PermissionLevelsToRemove "Full Control"

 

Using Set-SPOsiteGroup you can change the group permissions for a site by adding new permissions or removing existing permissions.

# List all users with access to a site Get-SPOUser -Site https://yourtenant.sharepoint.com/sites/sitename

Get-SPOUser allows you to check which users have access to your website.

 

Get-SPOUser -Site https://yourtenant.sharepoint.com/sites/nazwaWitryny Where-Object {$_.IsSiteAdmin -eq $false}

With the additional use of "Where-Object" you can extend this query, e.g. with the condition whether the user is not the owner of the website.

 

# Add a user to a group with site permissions Add-SPOUser -Site https://yourtenant.sharepoint.com/sites/sitename -LoginName user@yourtenant.com -Group "Contoso" # Remove a user from a group with site permissions Remove-SPOUser -Site https://yourtenant.sharepoint.com/sites/sitename -LoginName user@yourtenant.com -Group "Contoso"

 

The Add-SPOUser and Remove-SPOUser commands are particularly useful when managing a production environment. They can save you significant time, for example, when adding multiple users to a newly created website access group. Using a Foreach loop and a CSV file with user email addresses, you can accomplish this in seconds. Below is a sample script:

# Parameters $siteUrl = "https://yourtenant.sharepoint.com/sites/SiteName" $groupName = "Marketing" $csvPath = "C:\Path\To\File.csv" # Get the contents of the CSV file (the column with the Email header) $userEmails = Import-Csv $csvPath | Select-Object -ExpandProperty Email # Iterate through each email address and add it to the "Marketing" group foreach ($email in $userEmails) {    Add-SPOUser -Site $siteUrl -LoginName $email -Group $groupName    Write-Host "Added user $email to group $groupName" }



Automating Tasks Using PowerShell Scripts

Automating SharePoint processes using PowerShell is an effective strategy that allows organizations to optimize operations, increase efficiency, and reduce human error.

PowerShell allows you to create scripts to automate tasks such as adding, deleting, or modifying sites, lists, and libraries, as well as managing user permissions. For example, you can use a PowerShell script to create a new site, configure the document structure, or assign permission groups.

Additionally, PowerShell allows you to automate processes related to data migration in SharePoint. Using appropriate scripts, you can copy data between different sites, lists, or libraries, which is particularly important for scalable projects.

You can also schedule tasks using schedules in PowerShell, allowing you to regularly execute specific operations without requiring user interaction. This makes automation more comprehensive and eliminates the need for manual monitoring and triggering of processes.

However, before attempting to automate SharePoint processes using PowerShell, it's crucial to thoroughly understand the platform's structure and thoroughly test your scripts in a test environment. Additionally, it's a good idea to regularly update your scripts as changes are made to the SharePoint environment.

Summary

PowerShell in SharePoint Online is an indispensable tool for administrators who want to effectively manage their environment. An introduction to basic PowerShell commands and the automation of tasks using scripts enable a higher level of control and efficiency in managing sites, groups, users, and document resources. I encourage you to explore other commands and create your own scripts to tailor the tool to your organization's unique needs and simplify your daily work with SharePoint Online.

Robert Szarras - IT specialist
Related articles
Case study
| migrations and backups Case Study: Implementing Hardened Backup in Microsoft Azure. Read more
Article
| career Employee training and development in Support Online Read more
Article
| migrations and backups Veeam Hardened Repository – What is it and how does it protect backups against ransomware in 2026? Read more
Your IT.
our
support.
Contact us

The administrator of your personal data is Support Online sp. z o.o. Your personal data will be processed to respond to your inquiry and, if you consent, also to send the SOL newsletter. You can read about the detailed rules for personal data processing by our organization in our Privacy Policy.

FAQ

An IT company, or IT firm, deals with information technology in a broad sense. This includes, among other things:

  1. Software design and development: An IT company can create custom applications for other companies or software products for the mass market. Depending on their specialization, these can include mobile applications, desktop applications, web applications, or embedded systems.
  2. Consulting services: An IT company often provides experts to advise on implementing new technologies, optimizing business processes, or selecting appropriate technological solutions.
  3. Cloud solutions: Many IT companies specialize in implementing and managing cloud solutions, such as data storage, application hosting, and data analysis platforms.
  4. IT security: Protection against cyberattacks, security audits, implementing security policies, and network monitoring are just some of the IT companies' responsibilities in this area.
  5. IT infrastructure management: In this area, a company may manage servers, databases, networks, and endpoints.
  6. Technical Support and Service: An IT company may provide support for its own products or general IT support for other companies, managing their technology on a daily basis.
  7. Training: Many IT providers also offer training in software use and secure technology use.
  8. Hardware Solutions: Some IT companies may also provide and configure computer, server, or network hardware.

Depending on their specialization and size, an IT company may offer one, several, or all of the above solutions. When choosing a provider, it's important to thoroughly understand their services and tailor them to your individual needs.

At Support Online, we have been supporting companies for years with

  1. comprehensive user support (both on-site and remotely),
  2. we service computers, phones, tablets, and related network issues,
  3. we specialize in server administration: Windows, Linux/Unix,
  4. we support virtualizers such as KVM, Hyper-V, VMWare, and Proxmox,
  5. we support cloud services, particularly solutions such as Azure, Microsoft 365, and AWS,
  6. we monitor servers and devices on the internet,
  7. we consult on development, DRP, and support the stability of your business in the IT layer.

If you're looking for a good IT company, Support Online is the right place to grow your business.

It's worth using an IT company like Support Online when:

  1. You plan to implement new technologies or software in your company.
  2. You need specialized technology consulting.
  3. You want to optimize existing IT processes.
  4. You struggle with digital security issues.
  5. You need support in managing your IT infrastructure.
  6. You lack internal resources or expertise to implement certain technology projects.

Using external IT experts can bring benefits in terms of saving time and resources, and ensuring high-quality solutions.

Hiring an IT company like Support Online offers several key benefits over an IT freelancer:

  1. Support from the entire team: An IT company has a full team of specialists, from DevOps specialists and Cyber ​​Security Specialists to IT Helpdesk Specialists, who possess diverse skills and experience, enabling faster problem resolution and the implementation of more complex projects.
  2. Reliability and stability: IT companies have an established reputation and track record, which can translate into greater reliability and stability of services.
  3. Maintenance and support: An IT company can offer service contracts, warranties, and after-sales support, which may be more difficult to obtain from an individual freelancer.
  4. Resources: Companies have access to more resources, tools, and technologies that can accelerate and improve project execution.
  5. Long-term availability: The risk of a freelancer disappearing or changing careers is greater than the risk of a well-established company going out of business.

However, it's worth noting that the choice between a company and a freelancer depends on your specific needs and situation. If you value peace of mind and a quick response to unexpected problems, it is worth choosing an IT company such as Support Online.

Partnering with IT Support Online offers the following advantages:

  1. Professional IT outsourcing: The company guarantees high-quality IT outsourcing services for businesses of all sizes.
  2. Comprehensive IT support: IT Support Online provides comprehensive IT support that meets the diverse needs of businesses.
  3. Saves time and money: With our support, clients can focus on their core business activities while reducing the costs associated with information technology management.
  4. Serving a diverse range of businesses: The company specializes in serving both small and medium-sized enterprises and large corporations, demonstrating its flexibility and ability to adapt to diverse client needs.
  5. Leadership in IT outsourcing: The company is recognized as a leader in IT outsourcing, particularly in the Poznań and Warsaw regions.

By partnering with our company, IT Support Online, businesses can count on a high standard of service and professionalism at every stage of the relationship.

Free consultation
22 335 28 00