Skip to content

Commit fb00e7f

Browse files
Merge pull request KelvinTegelaar#1552 from kris6673/fix-SP-UTF8
Fix: Fix SharePoint site creation with UTF8 chars in it
2 parents be48b73 + 466cb6d commit fb00e7f

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Teams-Sharepoint/Invoke-AddSite.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-AddSite {
3+
function Invoke-AddSite {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -24,7 +24,7 @@ Function Invoke-AddSite {
2424
$StatusCode = [HttpStatusCode]::OK
2525
} catch {
2626
$StatusCode = [HttpStatusCode]::InternalServerError
27-
$Result = "Failed to create SharePoint Site: $($_.Exception.Message)"
27+
$Result = $_.Exception.Message
2828
}
2929

3030
# Associate values to output bindings by calling 'Push-OutputBinding'.

Modules/CIPPCore/Public/New-CIPPSharepointSite.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function New-CIPPSharepointSite {
3232
3333
#>
3434
[CmdletBinding(SupportsShouldProcess = $true)]
35-
Param(
35+
param(
3636
[Parameter(Mandatory = $true)]
3737
[string]$SiteName,
3838

@@ -139,37 +139,44 @@ function New-CIPPSharepointSite {
139139
'accept' = 'application/json;odata.metadata=none'
140140
'odata-version' = '4.0'
141141
}
142-
$Results = New-GraphPostRequest -scope "$($SharePointInfo.AdminUrl)/.default" -uri "$($SharePointInfo.AdminUrl)/_api/SPSiteManager/create" -Body ($body | ConvertTo-Json -Compress -Depth 10) -tenantid $TenantFilter -ContentType 'application/json' -AddedHeaders $AddedHeaders
142+
try {
143+
$Results = New-GraphPOSTRequest -scope "$($SharePointInfo.AdminUrl)/.default" -uri "$($SharePointInfo.AdminUrl)/_api/SPSiteManager/create" -body (ConvertTo-Json -Depth 10 -InputObject $body) -tenantid $TenantFilter -AddedHeaders $AddedHeaders
144+
} catch {
145+
$ErrorMessage = Get-CippException -Exception $_
146+
$Result = "Failed to create new SharePoint site $SiteName with URL $SiteUrl. Error: $($ErrorMessage.NormalizedError)"
147+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Error -LogData $ErrorMessage
148+
throw $Result
149+
}
143150
}
144151

145152
# Check the results. This response is weird. https://learn.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest
146153
switch ($Results.SiteStatus) {
147154
'0' {
148155
$Result = "Failed to create new SharePoint site $SiteName with URL $SiteUrl. The site doesn't exist."
149156
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Error
150-
throw $Results
157+
throw $Result
151158
}
152159
'1' {
153160
$Result = "Successfully created new SharePoint site $SiteName with URL $SiteUrl. The site is however currently being provisioned. Please wait for it to finish."
154161
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Info
155-
return $Results
162+
return $Result
156163
}
157164
'2' {
158165
$Result = "Successfully created new SharePoint site $SiteName with URL $SiteUrl"
159166
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Info
160-
return $Results
167+
return $Result
161168
}
162169
'3' {
163170
$Result = "Failed to create new SharePoint site $SiteName with URL $SiteUrl. An error occurred while provisioning the site."
164171
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Error
165-
throw $Results
172+
throw $Result
166173
}
167174
'4' {
168175
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -sev Error
169176
$Result = "Failed to create new SharePoint site $SiteName with URL $SiteUrl. The site already exists."
170177
throw $Result
171178
}
172-
Default {}
179+
default {}
173180
}
174181

175182

0 commit comments

Comments
 (0)