Managing Microsoft 365 SharePoint sites and content with PowerShell

Managing Microsoft 365 SharePoint sites and content with PowerShell


Managing Microsoft 365 SharePoint sites and content can be a challenging task, especially when dealing with large amounts of data. To simplify this process, administrators can take advantage of PowerShell scripting to automate various management tasks. Our advanced guide delves into the capabilities of PowerShell for managing Microsoft 365 SharePoint, providing practical examples and best practices to help you streamline your SharePoint management workflows. Whether you're an experienced PowerShell user or new to the platform, our guide covers everything from basic concepts to advanced SharePoint management techniques, enabling you to take full control of your SharePoint environment and improve productivity.

Set up the SharePoint Online Management Shell
Before we can start managing SharePoint sites with PowerShell, we need to set up the SharePoint Online Management Shell. Here's how:

Open PowerShell as an administrator and run the following command to install the SharePoint Online Management Shell:

  1. Install-Module -Name Microsoft.Online.SharePoint.PowerShell


After the module is installed, run the following command to connect to SharePoint:

  1. Connect-SPOService -Url https://zylker-admin.sharepoint.com


Replace "zylker" with your own organization's name.


Managing SharePoint sites


Now that we have set up the SharePoint Online Management Shell, we can start managing SharePoint sites with PowerShell. Here are some common tasks:

Create a new site:

  1. New-SPOSite -Url https://zylker.sharepoint.com/sites/finance -Title "Finance Site" -Template "STS#0"


This command creates a new site with the URL https://zylker.sharepoint.com/sites/finance, the title "Finance Site," and the template "STS#0."

Delete a site:

  1. Remove-SPOSite -Identity https://zylker.sharepoint.com/sites/finance -Confirm:$false


This command deletes the site with the URL https://zylker.sharepoint.com/sites/finance. The -Confirm:$false parameter suppresses the confirmation prompt.

Set site permissions:


  1. Set-SPOSite -Identity https://zylker.sharepoint.com/sites/finance -Owner "jane@zylker.com"


This command sets the owner of the site with the URL https://zylker.sharepoint.com/sites/finance to jane@zylker.com.

Get site information:

  1. Get-SPOSite -Identity https://zylker.sharepoint.com/sites/finance


This command retrieves information about the site with the URL https://zylker.sharepoint.com/sites/finance.

Managing SharePoint content


In addition to managing SharePoint sites, we can also manage SharePoint content with PowerShell. Here are some common tasks:


Create a new list:


  1. New-SPOList -Title "Announcements" -Template "Announcements" -Url "Lists/Announcements" -Description "Company Announcements"


This command creates a new list with the title "Announcements," the template "Announcements," the URL "Lists/Announcements," and the description "Company Announcements."

Delete a list:


  1. Remove-SPOList -Identity "Lists/Announcements" -Confirm:$false


This command deletes the list with the URL "Lists/Announcements." The -Confirm:$false parameter suppresses the confirmation prompt.

Set list permissions:


  1. Set-SPOList -Identity "Lists/Announcements" -BreakRoleInheritance -CopyRoleAssignments


This command breaks inheritance for the list with the URL "Lists/Announcements" and copies the role assignments from the parent site.

Get list information:


  1. Get-SPOList -Identity "Lists/Announcements"


This command retrieves information about the list with the URL "Lists/Announcements."

Add an item to a list:

  1. $list = Get-SPOList -Identity "Lists/Announcements"
  2. $itemProperties = @{
  3. "Title" = "New Announcement"
  4. "Body" = "This is a new announcement."
  5. }
  6. Add-SPOListItem -List $list -Values $itemProperties


This command adds a new item to the list with the title "New Announcement" and the body "This is a new announcement."

Delete an item from a list:

  1. $list=Get-SPOList-Identity"Lists/Announcements"
  2. $item=Get-SPOListItem-List$list-Id1
  3. Remove-SPOListItem-List$list-Identity$item-Confirm:$false


This command retrieves the first item from the list with the URL "Lists/Announcements" and deletes it. The -Confirm:$false parameter suppresses the confirmation prompt.

Update an item in a list:


  1. $list=Get-SPOList-Identity"Lists/Announcements"
  2. $item=Get-SPOListItem-List$list-Id2
  3. $itemProperties=@{
  4. "Title"="Updated Announcement"
  5. "Body"="This announcement has been updated."
  6. }
  7. Set-SPOListItem-List$list-Identity$item-Values$itemProperties


This command retrieves the second item from the list with the URL "Lists/Announcements" and updates its title and body.

Conclusion


PowerShell provides a powerful way to manage Microsoft 365 SharePoint sites and content. With PowerShell, we can automate common administrative tasks and perform them more efficiently. By following the steps outlined in this article, you should be able to manage SharePoint sites and content with ease.

    • Related Articles

    • Setting up and Managing Microsoft 365 SharePoint Online Sites

      Introduction Microsoft SharePoint Online is a cloud-based collaboration and document management platform that can help businesses manage their data, documents, and information more efficiently. SharePoint Online allows businesses to create sites, ...
    • Deep Dive into Microsoft 365 PowerShell Scripting

      Microsoft 365 lets administrators manage user accounts, licenses, settings, and more online via a web-based administrative console. Although the console provides a user-friendly interface for managing Microsoft 365, it can be complex when it comes to ...
    • Managing Microsoft 365 licenses using PowerShell

      Managing licenses for Microsoft 365 can be a daunting task, especially when you have a large number of users. However, PowerShell provides a powerful and efficient way to manage licenses in Microsoft 365. In this article, we will walk you through the ...
    • Microsoft 365 teams best practices

      Across all sizes of businesses, Microsoft Teams has become one of the most popular collaboration tools. Teams provides robust features that enable teams to collaborate and communicate effectively, regardless of their location. With so many features ...
    • Configuring and Managing Microsoft 365 Exchange Online: A Technical overview

      Microsoft 365 Exchange Online is a cloud-based email messaging service designed to meet the communication needs of businesses of all sizes. Configuring and managing Exchange Online can be a complex task, but with the right knowledge and tools, it can ...