diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index d01f12b..80e79da 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -37,7 +37,6 @@ function Save-Config { function Connect-SharePoint { try { - # Use current form values instead of saved config $siteUrl = $script:txtSiteUrl.Text $clientId = $config.ClientId $clientSecret = $config.ClientSecret @@ -46,11 +45,15 @@ function Connect-SharePoint { throw "Please enter a Site URL" } - Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret -WarningAction SilentlyContinue + Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret ` + -WarningAction SilentlyContinue ` + -Tenant "sutterhill" ` # Match your tenant name + -Scopes @("AllSites.FullControl") # Required for folder browsing + return $true } catch { - $script:txtStatus.Text += "Error connecting: $_`n" + $script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n" return $false } } @@ -131,29 +134,28 @@ function Move-Files { } } function Get-FolderBrowser { - param($context) try { if (-not (Connect-SharePoint)) { return $null } - $libraryName = $script:txtProdLib.Text - if (-not $libraryName) { - throw "Production Library name is required" + # 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" } - $ctx = Get-PnPConnection - $web = Get-PnPWeb - $library = Get-PnPList -Identity $libraryName + # Get folders with elevated permissions + $ctx = Get-PnPContext + $ctx.Load($library.RootFolder.Folders) + $ctx.ExecuteQuery() - $folders = Get-PnPFolder -Url $library.RootFolder.ServerRelativeUrl -Includes Folders | - Select-Object -ExpandProperty Folders | - Select-Object Name, ServerRelativeUrl - - return $folders | Out-GridView -Title "Select Folder (Double-click to select)" -PassThru + return $library.RootFolder.Folders | + Select-Object Name, ServerRelativeUrl | + Out-GridView -Title "Select Folder" -PassThru } catch { - $script:txtStatus.Text += "Error browsing folders: $_`n" + $script:txtStatus.Text += "Folder Error: $($_.Exception.Message)`n" return $null } } diff --git a/config.json b/config.json index 645ac60..a8deb60 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,6 @@ "ClientId": "dcb744a3-96ee-4521-bb35-9909146d3a13", "SiteUrl": "https://sutterhill.sharepoint.com/sites/tax", "ProductionLibrary": "Documents", - "ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso" + "ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso", + "TenantId": "sutterhill" }