Now stores the sites list so you can quickly modify your choices without reloading the whole list
This commit is contained in:
@@ -212,7 +212,9 @@ function Show-SitePicker {
|
|||||||
param(
|
param(
|
||||||
[string]$TenantUrl,
|
[string]$TenantUrl,
|
||||||
[string]$ClientId,
|
[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
|
$dlg = New-Object System.Windows.Forms.Form
|
||||||
@@ -333,6 +335,16 @@ function Show-SitePicker {
|
|||||||
ClientId = $ClientId
|
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)
|
# ItemChecked fires AFTER the checked state changes (unlike ItemCheck)
|
||||||
$lv.Add_ItemChecked({
|
$lv.Add_ItemChecked({
|
||||||
param($s, $e)
|
param($s, $e)
|
||||||
@@ -437,8 +449,10 @@ function Show-SitePicker {
|
|||||||
$script:_pkl.LblStatus.ForeColor = [System.Drawing.Color]::Red
|
$script:_pkl.LblStatus.ForeColor = [System.Drawing.Color]::Red
|
||||||
} else {
|
} else {
|
||||||
$script:_pkl.AllSites = @($script:_pkl.Sync.Sites)
|
$script:_pkl.AllSites = @($script:_pkl.Sync.Sites)
|
||||||
|
$script:_SiteCache = @($script:_pkl.Sync.Sites)
|
||||||
_Pkl-Sort
|
_Pkl-Sort
|
||||||
_Pkl-Repopulate
|
_Pkl-Repopulate
|
||||||
|
$script:_pkl.BtnLoad.Text = "Recharger"
|
||||||
$script:_pkl.BtnOK.Enabled = ($script:_pkl.Lv.Items.Count -gt 0)
|
$script:_pkl.BtnOK.Enabled = ($script:_pkl.Lv.Items.Count -gt 0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -451,8 +465,8 @@ function Show-SitePicker {
|
|||||||
|
|
||||||
$result = if ($Owner) { $dlg.ShowDialog($Owner) } else { $dlg.ShowDialog() }
|
$result = if ($Owner) { $dlg.ShowDialog($Owner) } else { $dlg.ShowDialog() }
|
||||||
|
|
||||||
if ($result -eq "OK") { return @($script:_pkl.CheckedUrls) }
|
if ($result -eq "OK") { return ,@($script:_pkl.CheckedUrls) }
|
||||||
return @()
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -1819,8 +1833,10 @@ Function Generate-PnPSitePermissionRpt {
|
|||||||
)
|
)
|
||||||
Try {
|
Try {
|
||||||
Write-Log "Connecting to SharePoint... (browser window will open)" "Yellow"
|
Write-Log "Connecting to SharePoint... (browser window will open)" "Yellow"
|
||||||
|
[System.Windows.Forms.Application]::DoEvents()
|
||||||
Connect-PnPOnline -Url $SiteURL -Interactive -ClientId $script:pnpCiD
|
Connect-PnPOnline -Url $SiteURL -Interactive -ClientId $script:pnpCiD
|
||||||
$Web = Get-PnPWeb
|
$Web = Get-PnPWeb
|
||||||
|
[System.Windows.Forms.Application]::DoEvents()
|
||||||
|
|
||||||
Write-Log "Getting Site Collection Administrators..." "Yellow"
|
Write-Log "Getting Site Collection Administrators..." "Yellow"
|
||||||
$SiteAdmins = Get-PnPSiteCollectionAdmin
|
$SiteAdmins = Get-PnPSiteCollectionAdmin
|
||||||
@@ -1862,9 +1878,7 @@ Function Generate-PnPSitePermissionRpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$i++
|
$i++
|
||||||
Write-Progress -PercentComplete ($i / [Math]::Max($Folders.Count,1) * 100) `
|
[System.Windows.Forms.Application]::DoEvents()
|
||||||
-Activity "Folders in '$($List.Title)'" `
|
|
||||||
-Status "'$($Folder.FieldValues.FileLeafRef)' ($i of $($Folders.Count))" -Id 2 -ParentId 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1888,9 +1902,7 @@ Function Generate-PnPSitePermissionRpt {
|
|||||||
If ($List.Hidden -eq $false -and $ExcludedLists -notcontains $List.Title) {
|
If ($List.Hidden -eq $false -and $ExcludedLists -notcontains $List.Title) {
|
||||||
$c++
|
$c++
|
||||||
Write-Log "`tList ($c/$($Lists.Count)): $($List.Title)" "Cyan"
|
Write-Log "`tList ($c/$($Lists.Count)): $($List.Title)" "Cyan"
|
||||||
Write-Progress -PercentComplete ($c / [Math]::Max($Lists.Count,1) * 100) `
|
[System.Windows.Forms.Application]::DoEvents()
|
||||||
-Activity "Scanning lists in $($Web.URL)" `
|
|
||||||
-Status "'$($List.Title)' ($c of $($Lists.Count))" -Id 1
|
|
||||||
If ($ScanFolders) { Get-PnPFolderPermission -List $List }
|
If ($ScanFolders) { Get-PnPFolderPermission -List $List }
|
||||||
If ($IncludeInheritedPermissions) { Get-PnPPermissions -Object $List }
|
If ($IncludeInheritedPermissions) { Get-PnPPermissions -Object $List }
|
||||||
Else {
|
Else {
|
||||||
@@ -1904,6 +1916,7 @@ Function Generate-PnPSitePermissionRpt {
|
|||||||
|
|
||||||
Function Get-PnPWebPermission([Microsoft.SharePoint.Client.Web]$Web) {
|
Function Get-PnPWebPermission([Microsoft.SharePoint.Client.Web]$Web) {
|
||||||
Write-Log "Processing web: $($Web.URL)" "Yellow"
|
Write-Log "Processing web: $($Web.URL)" "Yellow"
|
||||||
|
[System.Windows.Forms.Application]::DoEvents()
|
||||||
Get-PnPPermissions -Object $Web
|
Get-PnPPermissions -Object $Web
|
||||||
Write-Log "`tScanning lists and libraries..." "Yellow"
|
Write-Log "`tScanning lists and libraries..." "Yellow"
|
||||||
Get-PnPListPermission($Web)
|
Get-PnPListPermission($Web)
|
||||||
@@ -3060,8 +3073,31 @@ $tabs.TabPages.AddRange(@($tabPerms, $tabStorage, $tabTemplates, $tabSearch, $ta
|
|||||||
$progressBar = New-Object System.Windows.Forms.ProgressBar
|
$progressBar = New-Object System.Windows.Forms.ProgressBar
|
||||||
$progressBar.Location = New-Object System.Drawing.Point(20, 540)
|
$progressBar.Location = New-Object System.Drawing.Point(20, 540)
|
||||||
$progressBar.Size = New-Object System.Drawing.Size(642, 16)
|
$progressBar.Size = New-Object System.Drawing.Size(642, 16)
|
||||||
$progressBar.Style = "Marquee"
|
$progressBar.Style = "Continuous"
|
||||||
$progressBar.MarqueeAnimationSpeed = 0
|
$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 ────────────────────────────────────────────────────────────────────────
|
# ── Log ────────────────────────────────────────────────────────────────────────
|
||||||
$lblLog = New-Object System.Windows.Forms.Label
|
$lblLog = New-Object System.Windows.Forms.Label
|
||||||
@@ -3086,6 +3122,15 @@ $script:cboProfile = $cboProfile
|
|||||||
$script:btnBrowseSites = $btnBrowseSites
|
$script:btnBrowseSites = $btnBrowseSites
|
||||||
$script:Profiles = @()
|
$script:Profiles = @()
|
||||||
$script:SelectedSites = @()
|
$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(@(
|
$form.Controls.AddRange(@(
|
||||||
$menuStrip,
|
$menuStrip,
|
||||||
@@ -3341,13 +3386,31 @@ $btnBrowseSites.Add_Click({
|
|||||||
"Veuillez renseigner le Client ID.", "Client ID manquant", "OK", "Warning")
|
"Veuillez renseigner le Client ID.", "Client ID manquant", "OK", "Warning")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$selected = Show-SitePicker -TenantUrl $tenantUrl -ClientId $clientId -Owner $form
|
$selected = Show-SitePicker -TenantUrl $tenantUrl -ClientId $clientId -Owner $form `
|
||||||
if ($selected -and $selected.Count -gt 0) {
|
-InitialSites $script:_SiteCache `
|
||||||
|
-PreSelected $script:SelectedSites
|
||||||
|
if ($null -eq $selected) { return } # Cancel — ne rien changer
|
||||||
|
|
||||||
$script:SelectedSites = @($selected)
|
$script:SelectedSites = @($selected)
|
||||||
# Populate Site URL with first selection for compatibility
|
|
||||||
$txtSiteURL.Text = $selected[0]
|
|
||||||
$n = $selected.Count
|
$n = $selected.Count
|
||||||
$btnBrowseSites.Text = if ($n -eq 1) { "Voir les sites" } else { "Sites ($n)" }
|
|
||||||
|
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
|
$btnGenPerms.Enabled = $false
|
||||||
$btnOpenPerms.Enabled = $false
|
$btnOpenPerms.Enabled = $false
|
||||||
$txtLog.Clear()
|
$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 }
|
$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"
|
Write-Log "=== PERMISSIONS REPORT ===" "White"
|
||||||
@@ -3409,7 +3472,7 @@ $btnGenPerms.Add_Click({
|
|||||||
|
|
||||||
$script:PermOutputFile = $lastFile
|
$script:PermOutputFile = $lastFile
|
||||||
$btnGenPerms.Enabled = $true
|
$btnGenPerms.Enabled = $true
|
||||||
$progressBar.MarqueeAnimationSpeed = 0
|
Stop-ProgressAnim
|
||||||
})
|
})
|
||||||
|
|
||||||
$btnOpenPerms.Add_Click({
|
$btnOpenPerms.Add_Click({
|
||||||
@@ -3544,7 +3607,7 @@ function Start-NextStorageScan {
|
|||||||
if ($script:_StorSiteQueue.Count -eq 0) {
|
if ($script:_StorSiteQueue.Count -eq 0) {
|
||||||
Write-Log "=== All sites processed ===" "Cyan"
|
Write-Log "=== All sites processed ===" "Cyan"
|
||||||
$btnGenStorage.Enabled = $true
|
$btnGenStorage.Enabled = $true
|
||||||
$progressBar.MarqueeAnimationSpeed = 0
|
Stop-ProgressAnim
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3652,7 +3715,7 @@ $btnGenStorage.Add_Click({
|
|||||||
$btnGenStorage.Enabled = $false
|
$btnGenStorage.Enabled = $false
|
||||||
$btnOpenStorage.Enabled = $false
|
$btnOpenStorage.Enabled = $false
|
||||||
$txtLog.Clear()
|
$txtLog.Clear()
|
||||||
$progressBar.MarqueeAnimationSpeed = 30
|
Start-ProgressAnim
|
||||||
|
|
||||||
$depthLabel = if ($script:_StorDepth -ge 999) { "Maximum" } elseif ($script:_StorDepth -eq 0) { "N/A" } else { $script:_StorDepth }
|
$depthLabel = if ($script:_StorDepth -ge 999) { "Maximum" } elseif ($script:_StorDepth -eq 0) { "N/A" } else { $script:_StorDepth }
|
||||||
Write-Log "=== STORAGE METRICS ===" "White"
|
Write-Log "=== STORAGE METRICS ===" "White"
|
||||||
@@ -3726,7 +3789,7 @@ $btnSearch.Add_Click({
|
|||||||
$btnSearch.Enabled = $false
|
$btnSearch.Enabled = $false
|
||||||
$btnOpenSearch.Enabled = $false
|
$btnOpenSearch.Enabled = $false
|
||||||
$txtLog.Clear()
|
$txtLog.Clear()
|
||||||
$progressBar.MarqueeAnimationSpeed = 30
|
Start-ProgressAnim
|
||||||
Write-Log "=== RECHERCHE DE FICHIERS ===" "White"
|
Write-Log "=== RECHERCHE DE FICHIERS ===" "White"
|
||||||
Write-Log "Site : $siteUrl" "Gray"
|
Write-Log "Site : $siteUrl" "Gray"
|
||||||
if ($filters.Extensions.Count -gt 0) { Write-Log "Extensions : $($filters.Extensions -join ', ')" "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 { [void]$script:_SrchPS.EndInvoke($script:_SrchHnd) } catch {}
|
||||||
try { $script:_SrchRS.Close(); $script:_SrchRS.Dispose() } catch {}
|
try { $script:_SrchRS.Close(); $script:_SrchRS.Dispose() } catch {}
|
||||||
$btnSearch.Enabled = $true
|
$btnSearch.Enabled = $true
|
||||||
$progressBar.MarqueeAnimationSpeed = 0
|
Stop-ProgressAnim
|
||||||
|
|
||||||
if ($script:_SrchSync.Error) {
|
if ($script:_SrchSync.Error) {
|
||||||
Write-Log "Echec : $($script:_SrchSync.Error)" "Red"
|
Write-Log "Echec : $($script:_SrchSync.Error)" "Red"
|
||||||
@@ -3934,7 +3997,7 @@ $btnScanDupes.Add_Click({
|
|||||||
$btnScanDupes.Enabled = $false
|
$btnScanDupes.Enabled = $false
|
||||||
$btnOpenDupes.Enabled = $false
|
$btnOpenDupes.Enabled = $false
|
||||||
$txtLog.Clear()
|
$txtLog.Clear()
|
||||||
$progressBar.MarqueeAnimationSpeed = 30
|
Start-ProgressAnim
|
||||||
Write-Log "=== SCAN DE DOUBLONS ===" "White"
|
Write-Log "=== SCAN DE DOUBLONS ===" "White"
|
||||||
Write-Log "Mode : $($dupFilters.Mode)" "Gray"
|
Write-Log "Mode : $($dupFilters.Mode)" "Gray"
|
||||||
Write-Log "Site : $siteUrl" "Gray"
|
Write-Log "Site : $siteUrl" "Gray"
|
||||||
@@ -4099,7 +4162,7 @@ $btnScanDupes.Add_Click({
|
|||||||
try { [void]$script:_DupPS.EndInvoke($script:_DupHnd) } catch {}
|
try { [void]$script:_DupPS.EndInvoke($script:_DupHnd) } catch {}
|
||||||
try { $script:_DupRS.Close(); $script:_DupRS.Dispose() } catch {}
|
try { $script:_DupRS.Close(); $script:_DupRS.Dispose() } catch {}
|
||||||
$btnScanDupes.Enabled = $true
|
$btnScanDupes.Enabled = $true
|
||||||
$progressBar.MarqueeAnimationSpeed = 0
|
Stop-ProgressAnim
|
||||||
|
|
||||||
if ($script:_DupSync.Error) {
|
if ($script:_DupSync.Error) {
|
||||||
Write-Log "Echec : $($script:_DupSync.Error)" "Red"
|
Write-Log "Echec : $($script:_DupSync.Error)" "Red"
|
||||||
|
|||||||
Reference in New Issue
Block a user