-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #939 from JohnDuprey/dev
Sharepoint functions and misc tweaks
- Loading branch information
Showing
11 changed files
with
281 additions
and
19 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function Get-CIPPSPOTenant { | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$TenantFilter, | ||
[string]$SharepointPrefix | ||
) | ||
|
||
if (!$SharepointPrefix) { | ||
# get sharepoint admin site | ||
$tenantName = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/sites/root' -asApp $true -tenantid $TenantFilter).id.Split('.')[0] | ||
} else { | ||
$tenantName = $SharepointPrefix | ||
} | ||
$AdminUrl = "https://$($tenantName)-admin.sharepoint.com" | ||
|
||
# Query tenant settings | ||
$XML = @' | ||
<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SharePoint Online PowerShell (16.0.24908.0)" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="106" ObjectPathId="105" /><Query Id="107" ObjectPathId="105"><Query SelectAllProperties="true"><Properties /></Query></Query></Actions><ObjectPaths><Constructor Id="105" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request> | ||
'@ | ||
$AdditionalHeaders = @{ | ||
'Accept' = 'application/json;odata=verbose' | ||
} | ||
$Results = New-GraphPostRequest -scope "$AdminURL/.default" -tenantid $TenantFilter -Uri "$AdminURL/_vti_bin/client.svc/ProcessQuery" -Type POST -Body $XML -ContentType 'text/xml' -AddedHeaders $AdditionalHeaders | ||
|
||
$Results | Select-Object -Last 1 *, @{n = 'SharepointPrefix'; e = { $tenantName } }, @{n = 'TenantFilter'; e = { $TenantFilter } } | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
function New-CIPPSharepointSite { | ||
<# | ||
.SYNOPSIS | ||
Create a new SharePoint site | ||
.DESCRIPTION | ||
Create a new SharePoint site using the Modern REST API | ||
.PARAMETER SiteName | ||
The name of the site | ||
.PARAMETER SiteDescription | ||
The description of the site | ||
.PARAMETER SiteOwner | ||
The username of the site owner | ||
.PARAMETER TemplateName | ||
The template to use for the site. Default is Communication | ||
.PARAMETER SiteDesign | ||
The design to use for the site. Default is Topic | ||
.PARAMETER WebTemplateExtensionId | ||
The web template extension ID to use | ||
.PARAMETER SensitivityLabel | ||
The Purview sensitivity label to apply to the site | ||
.PARAMETER TenantFilter | ||
The tenant associated with the site | ||
#> | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
Param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$SiteName, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$SiteDescription, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$SiteOwner, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[ValidateSet('Communication', 'Team')] | ||
[string]$TemplateName = 'Communication', | ||
|
||
[Parameter(Mandatory = $false)] | ||
[ValidateSet('Topic', 'Showcase', 'Blank', 'Custom')] | ||
[string]$SiteDesign = 'Showcase', | ||
|
||
[Parameter(Mandatory = $false)] | ||
[ValidatePattern('(\{|\()?[A-Za-z0-9]{4}([A-Za-z0-9]{4}\-?){4}[A-Za-z0-9]{12}(\}|\()?')] | ||
[string]$WebTemplateExtensionId, | ||
|
||
[Parameter(Mandatory = $false)] | ||
[ValidatePattern('(\{|\()?[A-Za-z0-9]{4}([A-Za-z0-9]{4}\-?){4}[A-Za-z0-9]{12}(\}|\()?')] | ||
[string]$SensitivityLabel, | ||
|
||
[string]$Classification, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string]$TenantFilter | ||
) | ||
$tenantName = (New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/sites/root' -asApp $true -tenantid $TenantFilter).id.Split('.')[0] | ||
$AdminUrl = "https://$($tenantName)-admin.sharepoint.com" | ||
$SitePath = $SiteName -replace ' ' -replace '[^A-Za-z0-9-]' | ||
$SiteUrl = "https://$tenantName.sharepoint.com/sites/$SitePath" | ||
|
||
|
||
|
||
|
||
switch ($TemplateName) { | ||
'Communication' { | ||
$WebTemplate = 'SITEPAGEPUBLISHING#0' | ||
} | ||
'Team' { | ||
$WebTemplate = 'STS#0' | ||
} | ||
} | ||
|
||
$WebTemplateExtensionId = '00000000-0000-0000-0000-000000000000' | ||
$DefaultSiteDesignIds = @( '96c933ac-3698-44c7-9f4a-5fd17d71af9e', '6142d2a0-63a5-4ba0-aede-d9fefca2c767', 'f6cc5403-0d63-442e-96c0-285923709ffc') | ||
|
||
switch ($SiteDesign) { | ||
'Topic' { | ||
$SiteDesignId = '96c933ac-3698-44c7-9f4a-5fd17d71af9e' | ||
} | ||
'Showcase' { | ||
$SiteDesignId = '6142d2a0-63a5-4ba0-aede-d9fefca2c767' | ||
} | ||
'Blank' { | ||
$SiteDesignId = 'f6cc5403-0d63-442e-96c0-285923709ffc' | ||
} | ||
'Custom' { | ||
if ($WebTemplateExtensionId -match '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$') { | ||
if ($WebTemplateExtensionId -notin $DefaultSiteDesignIds) { | ||
$WebTemplateExtensionId = $SiteDesign | ||
$SiteDesignId = '00000000-0000-0000-0000-000000000000' | ||
} else { | ||
$SiteDesignId = $WebTemplateExtensionId | ||
} | ||
} else { | ||
$SiteDesignId = '96c933ac-3698-44c7-9f4a-5fd17d71af9e' | ||
} | ||
} | ||
} | ||
|
||
# Create the request body | ||
$Request = @{ | ||
Title = $SiteName | ||
Url = $SiteUrl | ||
Lcid = 1033 | ||
ShareByEmailEnabled = $false | ||
Description = $SiteDescription | ||
WebTemplate = $WebTemplate | ||
SiteDesignId = $SiteDesignId | ||
Owner = $SiteOwner | ||
WebTemplateExtensionId = $WebTemplateExtensionId | ||
} | ||
|
||
# Set the sensitivity label if provided | ||
if ($SensitivityLabel) { | ||
$Request.SensitivityLabel = $SensitivityLabel | ||
} | ||
if ($Classification) { | ||
$Request.Classification = $Classification | ||
} | ||
|
||
Write-Verbose ($Request | ConvertTo-Json -Compress -Depth 10) | ||
|
||
$body = @{ | ||
request = $Request | ||
} | ||
|
||
# Create the site | ||
if ($PSCmdlet.ShouldProcess($SiteName, 'Create new SharePoint site')) { | ||
$AddedHeaders = @{ | ||
'accept' = 'application/json;odata.metadata=none' | ||
'odata-version' = '4.0' | ||
} | ||
New-GraphPostRequest -scope "$AdminUrl/.default" -uri "$AdminUrl/_api/SPSiteManager/create" -Body ($body | ConvertTo-Json -Compress -Depth 10) -tenantid $TenantFilter -ContentType 'application/json' -AddedHeaders $AddedHeaders | ||
} | ||
} |
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
Oops, something went wrong.