fix: Improve site search in Get-FolderBrowser with better URL handling
This commit is contained in:
parent
aaabb11624
commit
3d170f3652
@ -112,12 +112,24 @@ function Get-FolderBrowser {
|
|||||||
try {
|
try {
|
||||||
# Get site ID first
|
# Get site ID first
|
||||||
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
|
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
|
||||||
$site = Get-MgSite -Search $siteUrl | Where-Object { $_.WebUrl -eq $siteUrl }
|
# Extract site path from URL
|
||||||
|
$sitePathMatch = $siteUrl -match "sharepoint\.com(.*)"
|
||||||
|
if (-not $sitePathMatch) {
|
||||||
|
throw "Invalid SharePoint URL format"
|
||||||
|
}
|
||||||
|
$sitePath = $matches[1]
|
||||||
|
|
||||||
|
# Get site directly using path
|
||||||
|
$site = Get-MgSite -SiteId "root" -Property "siteCollection,webUrl,id" -ErrorAction Stop
|
||||||
|
$site = Get-MgSite -SiteId $site.Id -Property "siteCollection,webUrl,id" -ErrorAction Stop `
|
||||||
|
-Filter "startswith(webUrl, '$siteUrl')"
|
||||||
|
|
||||||
if (-not $site) {
|
if (-not $site) {
|
||||||
throw "Site not found"
|
throw "Site not found at $siteUrl"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$script:txtStatus.Text += "Found site: $($site.WebUrl)`n"
|
||||||
|
|
||||||
# Get drive (document library)
|
# Get drive (document library)
|
||||||
$drives = Get-MgSiteDrive -SiteId $site.Id
|
$drives = Get-MgSiteDrive -SiteId $site.Id
|
||||||
# Handle "Shared Documents" special case
|
# Handle "Shared Documents" special case
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user