Last active
March 4, 2024 17:09
-
-
Save jaloplo/2d99c237741a10e121462b86ba3cfb2a to your computer and use it in GitHub Desktop.
PowerShell script for registering a new container type in a consumer tenant.
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 | |
Registers a new container type in a consumer tenant. | |
.DESCRIPTION | |
This script connects to SharePoint Online and registers a new container type. | |
.PARAMETER SpoAdminUrl | |
SharePoint Online Central Administration URL. | |
.PARAMETER ContainerTypeName | |
Name of the container type to register. | |
.PARAMETER EntraAppId | |
Microsoft Entra application ID. | |
.PARAMETER AzureSubscriptionId | |
Azure subscription ID. | |
.PARAMETER ResourceGroupName | |
Name of the Azure resource group. | |
.PARAMETER ResourceGroupRegion | |
Azure region of the resource group. | |
.EXAMPLE | |
.\Create-SPOContainerType.ps1 -SpoAdminUrl "https://contoso-admin.sharepoint.com" -ContainerTypeName "MyContainerType" -EntraAppId "abc123" -AzureSubscriptionId "xyz456" -ResourceGroupName "ResourceGroup1" -ResourceGroupRegion "East US" | |
#> | |
param( | |
[Parameter(Mandatory=$true)] | |
[String] $SpoAdminUrl, | |
[Parameter(Mandatory=$true)] | |
[String] $ContainerTypeName, | |
[Parameter(Mandatory=$true)] | |
[String] $EntraAppId, | |
[Parameter(Mandatory=$true)] | |
[String] $AzureSubscriptionId, | |
[Parameter(Mandatory=$true)] | |
[String] $ResourceGroupName, | |
[Parameter(Mandatory=$true)] | |
[String] $ResourceGroupRegion | |
) | |
# Install SharePoint Online module | |
$moduleName = "Microsoft.Online.SharePoint.PowerShell" | |
Write-Host "Checking if module $moduleName is installed..." | |
$moduleInstalled = Get-Module -Name $moduleName -ListAvailable | |
if (-not $moduleInstalled) { | |
Write-Host "Module $moduleName is not installed. Installing..." | |
# Install module | |
Install-Module -Name $moduleName -Force -AllowClobber | |
} | |
# Check if module is imported, and import if not | |
$moduleImported = Get-Module -Name $moduleName -ErrorAction SilentlyContinue | |
if (-not $moduleImported) { | |
Write-Host "Module $moduleName is not imported. Importing..." | |
Import-Module $moduleName -Force | |
} | |
# Connect to SharePoint Online | |
Write-Host "Connecting to SharePoint Online..." | |
Connect-SPOService -Url $SpoAdminUrl | |
# Register the container type | |
Write-Host "Creating the container type..." | |
$containerType = New-SPOContainerType -TrialContainerType ` | |
-ContainerTypeName $ContainerTypeName ` | |
-OwningApplicationId $EntraAppId ` | |
-AzureSubscriptionId $AzureSubscriptionId ` | |
-ResourceGroup $ResourceGroupName ` | |
-Region $ResourceGroupRegion | |
# Output the container type | |
Write-Host "Container type created. Here it is the data:" | |
$containerType |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment