Microsoft365DSC
Microsoft365DSC copied to clipboard
MSFT_SPOSite.psm1: optimize/extend - Code not resistant to "bots" and other non-base URL sites
Description of the issue
MSFT_SPOSite.psm1 fails when a bot or other service with non-tenant URL is in Site list.
Proposed solution (add code in line 936, above "$site = Get-PnPTenantSite -Identity $site.Url" :
$compareUrl = "https://" + ($TenantId -split ".")[0]
if (!( ($site.Url).StartsWith($compareUrl) )) { Write-Verbose -Message "The specified siteURL {$site.URL} is not for your tenant and will return an error, next item."; continue }
Effect: Foreach $site is only executed when $site.url starts with correct baseURL. If not correct, "continue" is called and current line is skipped.
Microsoft 365 DSC Version
1.23.1213.1
Which workloads are affected
SharePoint Online
The DSC configuration
No response
Verbose logs showing the problem
[2024-01-04 01:31:35]
{InvalidOperation}
System.Management.Automation.PSInvalidOperationException: De site-URL bot189315-002 verwijst niet naar een domein in deze tenant.
bij PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord()
bij PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
bij System.Management.Automation.Cmdlet.DoProcessRecord()
bij System.Management.Automation.CommandProcessor.ProcessRecord()
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1213.1\DSCResources\MSFT_SPOSite\MSFT_SPOSite.psm1: line 935
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1213.1\modules\M365DSCReverse.psm1: line 639
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.1213.1\modules\M365DSCUtil.psm1: line 1314
at <ScriptBlock>, <No file>: line 1
TenantId: **********.onmicrosoft.com
Environment Information + PowerShell Version
OsName : Microsoft Windows 11 Pro
OsOperatingSystemSKU : 48
OsArchitecture : 64 bits
WindowsVersion : 2009
WindowsBuildLabEx : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage : nl-NL
OsMuiLanguages : {nl-NL}
Key : PSVersion
Value : 5.1.22621.2506
Name : PSVersion
Key : PSEdition
Value : Desktop
Name : PSEdition
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions
Key : BuildVersion
Value : 10.0.22621.2506
Name : BuildVersion
Key : CLRVersion
Value : 4.0.30319.42000
Name : CLRVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
Could you share some more details about the "bot" site? I haven't seen this before and am curious, what's behind. Thanks!
Hi Andi,
Sure i can. When using the powershell "Get-PnPTenantSite", the first result is a non-organisation baseURL:
PS C:\Windows\system32> Get-PnPTenantSite
Url Template LocaleId
http://bot189315-002/sites/<> STS#-1 1033
.....
.....
This breaks the "MSFT_SPOSite.psm1" script because you cannot request non-org baseURL sites in the Get-PnPTenantSite instruction.
PS C:\Windows\system32> Get-PnPTenantSite -Url http://bot189315-002/sites/<
- Get-PnPTenantSite -Url http://bot189315-002/sites/<
> -
+ CategoryInfo : InvalidOperation: (:) [Get-PnPTenantSite], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.GetTenantSite
Translated error: The managed path sites/URL is not a managed path in this tenant
Note; This "dummy" site is not visible in the Sharepoint GUI, only in Powershell/Graph.
What would create this bot URL? Is this really functional or does it hold any valuable information?