From ac97026100176bbaf21a7ba738020a6b92fda5d3 Mon Sep 17 00:00:00 2001 From: Kawa Date: Tue, 10 Mar 2026 14:18:07 +0100 Subject: [PATCH] Now stores the sites list so you can quickly modify your choices without reloading the whole list --- Sharepoint_ToolBox.ps1 | 115 +++++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 26 deletions(-) diff --git a/Sharepoint_ToolBox.ps1 b/Sharepoint_ToolBox.ps1 index b25cfd9..8d81b2f 100644 --- a/Sharepoint_ToolBox.ps1 +++ b/Sharepoint_ToolBox.ps1 @@ -212,7 +212,9 @@ function Show-SitePicker { param( [string]$TenantUrl, [string]$ClientId, - [System.Windows.Forms.Form]$Owner = $null + [System.Windows.Forms.Form]$Owner = $null, + [object[]]$InitialSites = @(), + [string[]]$PreSelected = @() ) $dlg = New-Object System.Windows.Forms.Form @@ -333,6 +335,16 @@ function Show-SitePicker { ClientId = $ClientId } + # Pre-populate from cache + restore previous selection + if ($InitialSites -and $InitialSites.Count -gt 0) { + $script:_pkl.AllSites = @($InitialSites) + foreach ($url in $PreSelected) { [void]$script:_pkl.CheckedUrls.Add($url) } + $btnLoad.Text = "Recharger" + _Pkl-Sort + _Pkl-Repopulate + $script:_pkl.BtnOK.Enabled = $true + } + # ItemChecked fires AFTER the checked state changes (unlike ItemCheck) $lv.Add_ItemChecked({ param($s, $e) @@ -437,8 +449,10 @@ function Show-SitePicker { $script:_pkl.LblStatus.ForeColor = [System.Drawing.Color]::Red } else { $script:_pkl.AllSites = @($script:_pkl.Sync.Sites) + $script:_SiteCache = @($script:_pkl.Sync.Sites) _Pkl-Sort _Pkl-Repopulate + $script:_pkl.BtnLoad.Text = "Recharger" $script:_pkl.BtnOK.Enabled = ($script:_pkl.Lv.Items.Count -gt 0) } } else { @@ -451,8 +465,8 @@ function Show-SitePicker { $result = if ($Owner) { $dlg.ShowDialog($Owner) } else { $dlg.ShowDialog() } - if ($result -eq "OK") { return @($script:_pkl.CheckedUrls) } - return @() + if ($result -eq "OK") { return ,@($script:_pkl.CheckedUrls) } + return $null } #endregion @@ -1819,8 +1833,10 @@ Function Generate-PnPSitePermissionRpt { ) Try { Write-Log "Connecting to SharePoint... (browser window will open)" "Yellow" + [System.Windows.Forms.Application]::DoEvents() Connect-PnPOnline -Url $SiteURL -Interactive -ClientId $script:pnpCiD $Web = Get-PnPWeb + [System.Windows.Forms.Application]::DoEvents() Write-Log "Getting Site Collection Administrators..." "Yellow" $SiteAdmins = Get-PnPSiteCollectionAdmin @@ -1862,9 +1878,7 @@ Function Generate-PnPSitePermissionRpt { } } $i++ - Write-Progress -PercentComplete ($i / [Math]::Max($Folders.Count,1) * 100) ` - -Activity "Folders in '$($List.Title)'" ` - -Status "'$($Folder.FieldValues.FileLeafRef)' ($i of $($Folders.Count))" -Id 2 -ParentId 1 + [System.Windows.Forms.Application]::DoEvents() } } @@ -1888,9 +1902,7 @@ Function Generate-PnPSitePermissionRpt { If ($List.Hidden -eq $false -and $ExcludedLists -notcontains $List.Title) { $c++ Write-Log "`tList ($c/$($Lists.Count)): $($List.Title)" "Cyan" - Write-Progress -PercentComplete ($c / [Math]::Max($Lists.Count,1) * 100) ` - -Activity "Scanning lists in $($Web.URL)" ` - -Status "'$($List.Title)' ($c of $($Lists.Count))" -Id 1 + [System.Windows.Forms.Application]::DoEvents() If ($ScanFolders) { Get-PnPFolderPermission -List $List } If ($IncludeInheritedPermissions) { Get-PnPPermissions -Object $List } Else { @@ -1904,6 +1916,7 @@ Function Generate-PnPSitePermissionRpt { Function Get-PnPWebPermission([Microsoft.SharePoint.Client.Web]$Web) { Write-Log "Processing web: $($Web.URL)" "Yellow" + [System.Windows.Forms.Application]::DoEvents() Get-PnPPermissions -Object $Web Write-Log "`tScanning lists and libraries..." "Yellow" Get-PnPListPermission($Web) @@ -3060,8 +3073,31 @@ $tabs.TabPages.AddRange(@($tabPerms, $tabStorage, $tabTemplates, $tabSearch, $ta $progressBar = New-Object System.Windows.Forms.ProgressBar $progressBar.Location = New-Object System.Drawing.Point(20, 540) $progressBar.Size = New-Object System.Drawing.Size(642, 16) -$progressBar.Style = "Marquee" -$progressBar.MarqueeAnimationSpeed = 0 +$progressBar.Style = "Continuous" +$progressBar.Minimum = 0 +$progressBar.Maximum = 100 +$progressBar.Value = 0 +$progressBar.Visible = $false + +# Animation timer: sweeps 0→100 then resets, driven by UI-thread timer +$script:_AnimTimer = New-Object System.Windows.Forms.Timer +$script:_AnimTimer.Interval = 30 # ~33 fps +$script:_AnimTimer.Add_Tick({ + $v = $progressBar.Value + 2 + if ($v -gt 100) { $v = 0 } + $progressBar.Value = $v +}) + +function Start-ProgressAnim { + $progressBar.Value = 0 + $progressBar.Visible = $true + $script:_AnimTimer.Start() +} +function Stop-ProgressAnim { + $script:_AnimTimer.Stop() + $progressBar.Value = 0 + $progressBar.Visible = $false +} # ── Log ──────────────────────────────────────────────────────────────────────── $lblLog = New-Object System.Windows.Forms.Label @@ -3086,6 +3122,15 @@ $script:cboProfile = $cboProfile $script:btnBrowseSites = $btnBrowseSites $script:Profiles = @() $script:SelectedSites = @() +$script:_SiteCache = @() + +# Si l'utilisateur re-saisit manuellement, effacer la multi-sélection du picker +$txtSiteURL.Add_TextChanged({ + if ($txtSiteURL.Enabled -and $script:SelectedSites.Count -gt 0) { + $script:SelectedSites = @() + $btnBrowseSites.Text = T "btn.view.sites" + } +}) $form.Controls.AddRange(@( $menuStrip, @@ -3341,13 +3386,31 @@ $btnBrowseSites.Add_Click({ "Veuillez renseigner le Client ID.", "Client ID manquant", "OK", "Warning") return } - $selected = Show-SitePicker -TenantUrl $tenantUrl -ClientId $clientId -Owner $form - if ($selected -and $selected.Count -gt 0) { - $script:SelectedSites = @($selected) - # Populate Site URL with first selection for compatibility - $txtSiteURL.Text = $selected[0] - $n = $selected.Count - $btnBrowseSites.Text = if ($n -eq 1) { "Voir les sites" } else { "Sites ($n)" } + $selected = Show-SitePicker -TenantUrl $tenantUrl -ClientId $clientId -Owner $form ` + -InitialSites $script:_SiteCache ` + -PreSelected $script:SelectedSites + if ($null -eq $selected) { return } # Cancel — ne rien changer + + $script:SelectedSites = @($selected) + $n = $selected.Count + + if ($n -gt 1) { + # Plusieurs sites : griser le champ + $txtSiteURL.Text = "" + $txtSiteURL.Enabled = $false + $txtSiteURL.BackColor = [System.Drawing.Color]::FromArgb(224, 224, 224) + $btnBrowseSites.Text = "Sites ($n)" + } elseif ($n -eq 1) { + $txtSiteURL.Text = $selected[0] + $txtSiteURL.Enabled = $true + $txtSiteURL.BackColor = [System.Drawing.Color]::White + $btnBrowseSites.Text = T "btn.view.sites" + } else { + # 0 sélectionnés (OK avec rien) — réinitialiser + $txtSiteURL.Text = "" + $txtSiteURL.Enabled = $true + $txtSiteURL.BackColor = [System.Drawing.Color]::White + $btnBrowseSites.Text = T "btn.view.sites" } }) @@ -3373,7 +3436,7 @@ $btnGenPerms.Add_Click({ $btnGenPerms.Enabled = $false $btnOpenPerms.Enabled = $false $txtLog.Clear() - $progressBar.MarqueeAnimationSpeed = 30 + Start-ProgressAnim $depthLabel = if ($script:PermFolderDepth -ge 999) { "Maximum" } elseif ($script:PermFolderDepth -eq 0) { "N/A (folder scan off)" } else { $script:PermFolderDepth } Write-Log "=== PERMISSIONS REPORT ===" "White" @@ -3409,7 +3472,7 @@ $btnGenPerms.Add_Click({ $script:PermOutputFile = $lastFile $btnGenPerms.Enabled = $true - $progressBar.MarqueeAnimationSpeed = 0 + Stop-ProgressAnim }) $btnOpenPerms.Add_Click({ @@ -3544,7 +3607,7 @@ function Start-NextStorageScan { if ($script:_StorSiteQueue.Count -eq 0) { Write-Log "=== All sites processed ===" "Cyan" $btnGenStorage.Enabled = $true - $progressBar.MarqueeAnimationSpeed = 0 + Stop-ProgressAnim return } @@ -3652,7 +3715,7 @@ $btnGenStorage.Add_Click({ $btnGenStorage.Enabled = $false $btnOpenStorage.Enabled = $false $txtLog.Clear() - $progressBar.MarqueeAnimationSpeed = 30 + Start-ProgressAnim $depthLabel = if ($script:_StorDepth -ge 999) { "Maximum" } elseif ($script:_StorDepth -eq 0) { "N/A" } else { $script:_StorDepth } Write-Log "=== STORAGE METRICS ===" "White" @@ -3726,7 +3789,7 @@ $btnSearch.Add_Click({ $btnSearch.Enabled = $false $btnOpenSearch.Enabled = $false $txtLog.Clear() - $progressBar.MarqueeAnimationSpeed = 30 + Start-ProgressAnim Write-Log "=== RECHERCHE DE FICHIERS ===" "White" Write-Log "Site : $siteUrl" "Gray" if ($filters.Extensions.Count -gt 0) { Write-Log "Extensions : $($filters.Extensions -join ', ')" "Gray" } @@ -3851,7 +3914,7 @@ $btnSearch.Add_Click({ try { [void]$script:_SrchPS.EndInvoke($script:_SrchHnd) } catch {} try { $script:_SrchRS.Close(); $script:_SrchRS.Dispose() } catch {} $btnSearch.Enabled = $true - $progressBar.MarqueeAnimationSpeed = 0 + Stop-ProgressAnim if ($script:_SrchSync.Error) { Write-Log "Echec : $($script:_SrchSync.Error)" "Red" @@ -3934,7 +3997,7 @@ $btnScanDupes.Add_Click({ $btnScanDupes.Enabled = $false $btnOpenDupes.Enabled = $false $txtLog.Clear() - $progressBar.MarqueeAnimationSpeed = 30 + Start-ProgressAnim Write-Log "=== SCAN DE DOUBLONS ===" "White" Write-Log "Mode : $($dupFilters.Mode)" "Gray" Write-Log "Site : $siteUrl" "Gray" @@ -4099,7 +4162,7 @@ $btnScanDupes.Add_Click({ try { [void]$script:_DupPS.EndInvoke($script:_DupHnd) } catch {} try { $script:_DupRS.Close(); $script:_DupRS.Dispose() } catch {} $btnScanDupes.Enabled = $true - $progressBar.MarqueeAnimationSpeed = 0 + Stop-ProgressAnim if ($script:_DupSync.Error) { Write-Log "Echec : $($script:_DupSync.Error)" "Red"