refactor: Update Get-FolderBrowser to use Graph API instead of PnP

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:38:22 -08:00
parent df82840f99
commit 2752601537

View File

@ -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 folders with elevated permissions
$ctx = Get-PnPContext
$ctx.Load($library.RootFolder.Folders)
$ctx.ExecuteQuery()
# Get drive (document library)
$drives = Get-MgSiteDrive -SiteId $site.Id
$drive = $drives | Where-Object { $_.Name -eq $script:txtProdLib.Text }
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 {