Created
March 20, 2024 17:14
-
-
Save jaloplo/7d6242933350b3871a73617f147b7193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Script to create a new list or document library in SharePoint Online. | |
.DESCRIPTION | |
This script connects to SharePoint Online using the specified SiteURL and creates a new list or document library based on the provided parameters. | |
.PARAMETER SiteURL | |
The URL of the SharePoint site where the list or document library will be created. | |
.PARAMETER Name | |
The name of the list or document library to be created. | |
.PARAMETER Type | |
Specify 'List' to create a list or 'DocumentLibrary' to create a document library. | |
.EXAMPLE | |
Create a new list named "Projects": | |
.\New-SPOList.ps1 -SiteURL "https://yourtenant.sharepoint.com/sites/yoursite" -Name "Projects" -Type List | |
.EXAMPLE | |
Create a new document library named "Documents": | |
.\New-SPOList.ps1 -SiteURL "https://yourtenant.sharepoint.com/sites/yoursite" -Name "Documents" -Type DocumentLibrary | |
#> | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$SiteURL, | |
[Parameter(Mandatory=$true)] | |
[string]$Name, | |
[Parameter(Mandatory=$true)] | |
[ValidateSet("List", "DocumentLibrary")] | |
[string]$Type # Specify 'List' for a list or 'DocumentLibrary' for a document library | |
) | |
# Connect to SharePoint Online using the specified SiteURL | |
Connect-PnPOnline -Url $SiteURL -Interactive | |
# Create a new list or document library based on the specified type | |
if ($Type -eq "List") { | |
# Create a new list in SharePoint Online | |
New-PnPList -Title $Name -Url "Lists/$Name" -Template GenericList | |
Write-Host "List '$Name' has been created successfully!" -ForegroundColor Green | |
} | |
elseif ($Type -eq "DocumentLibrary") { | |
# Create a new document library in SharePoint Online | |
New-PnPList -Title $Name -Url "Documents/$Name" -Template DocumentLibrary | |
Write-Host "Document Library '$Name' has been created successfully!" -ForegroundColor Green | |
} | |
else { | |
Write-Host "Invalid list type specified. Please provide 'List' or 'DocumentLibrary' as the type parameter." -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment