diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 336a7de..3ac1e61 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -110,19 +110,35 @@ function Move-Files { } function Get-FolderBrowser { try { - # Verify library exists and is accessible - $library = Get-PnPList -Identity $script:txtProdLib.Text -Includes RootFolder,HasUniqueRoleAssignments - if ($library.HasUniqueRoleAssignments) { - throw "This library has unique permissions - verify app has access" + # Get site ID first + $siteUrl = $script:txtSiteUrl.Text + $site = Get-MgSite -Search $siteUrl | Where-Object { $_.WebUrl -eq $siteUrl } + + if (-not $site) { + throw "Site not found" } + + # Get drive (document library) + $drives = Get-MgSiteDrive -SiteId $site.Id + $drive = $drives | Where-Object { $_.Name -eq $script:txtProdLib.Text } - # Get folders with elevated permissions - $ctx = Get-PnPContext - $ctx.Load($library.RootFolder.Folders) - $ctx.ExecuteQuery() - - return $library.RootFolder.Folders | - Select-Object Name, ServerRelativeUrl | + if (-not $drive) { + throw "Library not found" + } + + # Get folders + $folders = Get-MgDriveRoot -DriveId $drive.Id | Get-MgDriveItemChild -DriveId $drive.Id + $folders = $folders | Where-Object { $_.Folder } + + # Create custom objects for the grid view + $folderObjects = $folders | ForEach-Object { + [PSCustomObject]@{ + Name = $_.Name + ServerRelativeUrl = "/sites/$($site.Name)/$($drive.Name)/$($_.Name)" + } + } + + return $folderObjects | Out-GridView -Title "Select Folder" -PassThru } catch {