refactor: Update Get-FolderBrowser to use Graph API instead of PnP
This commit is contained in:
parent
df82840f99
commit
2752601537
@ -110,19 +110,35 @@ function Move-Files {
|
|||||||
}
|
}
|
||||||
function Get-FolderBrowser {
|
function Get-FolderBrowser {
|
||||||
try {
|
try {
|
||||||
# Verify library exists and is accessible
|
# Get site ID first
|
||||||
$library = Get-PnPList -Identity $script:txtProdLib.Text -Includes RootFolder,HasUniqueRoleAssignments
|
$siteUrl = $script:txtSiteUrl.Text
|
||||||
if ($library.HasUniqueRoleAssignments) {
|
$site = Get-MgSite -Search $siteUrl | Where-Object { $_.WebUrl -eq $siteUrl }
|
||||||
throw "This library has unique permissions - verify app has access"
|
|
||||||
|
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
|
if (-not $drive) {
|
||||||
$ctx = Get-PnPContext
|
throw "Library not found"
|
||||||
$ctx.Load($library.RootFolder.Folders)
|
}
|
||||||
$ctx.ExecuteQuery()
|
|
||||||
|
# Get folders
|
||||||
return $library.RootFolder.Folders |
|
$folders = Get-MgDriveRoot -DriveId $drive.Id | Get-MgDriveItemChild -DriveId $drive.Id
|
||||||
Select-Object Name, ServerRelativeUrl |
|
$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
|
Out-GridView -Title "Select Folder" -PassThru
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user