From 57917e9183e8a1a2646ceec78e1a39cfbaadff7f Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Tue, 24 Nov 2026 13:12:12 +0100 Subject: [PATCH] feat(toolkit): use the folder picker for launcher path prompts Move the fzf folder browser to Scripts/Private/Select-FolderPath.ps1 so the launcher can use it too. Full tenant export root, tenant A and B export folders and the report folder of the offline compare, the earlier-export choice of the drift check and the report paths now open the picker. It starts at the nearest existing folder, falls back to a plain prompt without fzf and understands ~ and quotes. --- CHANGELOG_macOS_IntuneToolkit.md | 8 ++ Scripts/Private/Select-FolderPath.ps1 | 63 ++++++++++++++++ Scripts/Private/Start-IntuneManagementTui.ps1 | 44 +---------- Start-IntuneToolkit.ps1 | 75 ++++++++++--------- 4 files changed, 110 insertions(+), 80 deletions(-) create mode 100644 Scripts/Private/Select-FolderPath.ps1 diff --git a/CHANGELOG_macOS_IntuneToolkit.md b/CHANGELOG_macOS_IntuneToolkit.md index 732a025..f04e09b 100644 --- a/CHANGELOG_macOS_IntuneToolkit.md +++ b/CHANGELOG_macOS_IntuneToolkit.md @@ -1,5 +1,13 @@ # macOS Intune Toolkit Changelog +## 2026-11-24 — v4.6.2 — Folder picker in the launcher + +### Changed +- **`Scripts/Private/Select-FolderPath.ps1`** (new, shared) + - The fzf folder browser (browse, create new folder, type a path) moved out of the TUI script so the launcher can use it too. When the start path does not exist it opens at the nearest existing parent. Without `fzf` it falls back to a plain prompt, with `~` and quotes handled and an optional default. +- **`Start-IntuneToolkit.ps1`** + - Folder prompts now use the picker: export root of *Full tenant export*, the export folders of tenants A and B plus the output folder in *Compare two tenant exports* (B opens next to A), the earlier-export choice of the drift check (answer `b`), and the paths in *Generate reports*. + ## 2026-11-24 — v4.6.1 — Sequential menu numbers ### Changed diff --git a/Scripts/Private/Select-FolderPath.ps1 b/Scripts/Private/Select-FolderPath.ps1 new file mode 100644 index 0000000..773fff4 --- /dev/null +++ b/Scripts/Private/Select-FolderPath.ps1 @@ -0,0 +1,63 @@ +# Interactive folder picker shared by the launcher and the TUI. +# With fzf: browse folders, create a new one, or type a path. Without fzf: plain prompt. +# Returns the chosen full path, or $null when cancelled (Esc / empty input and no default). + +function ConvertTo-FullFolderPath +{ + param([string]$Path) + if([string]::IsNullOrWhiteSpace($Path)) { return $null } + $p = $Path.Trim().Trim('"', "'") -replace '^~', $HOME + [IO.Path]::GetFullPath($p) +} + +function Select-FolderPath +{ + param( + [Parameter(Mandatory)] + [string]$Prompt, + [string]$StartPath = (Get-Location).Path, + # Used when the fallback prompt gets an empty answer + [string]$Default + ) + + if(-not (Get-Command fzf -ErrorAction SilentlyContinue)) + { + $suffix = if($Default) { " (Enter = $Default)" } else { "" } + $typed = Read-Host "$Prompt$suffix" + if([string]::IsNullOrWhiteSpace($typed)) { $typed = $Default } + return (ConvertTo-FullFolderPath $typed) + } + + # Start at the nearest folder that exists (the default root may not exist yet) + $current = ConvertTo-FullFolderPath $StartPath + while($current -and -not (Test-Path -LiteralPath $current -PathType Container)) { $current = Split-Path -Path $current -Parent } + if(-not $current) { $current = (Get-Location).Path } + + while($true) + { + $entries = @("[Use this folder]", "[Create new folder]", "[Type path manually]") + $parent = Split-Path -Path $current -Parent + if($parent) { $entries += ".." } + $entries += Get-ChildItem -LiteralPath $current -Directory -ErrorAction SilentlyContinue | Sort-Object Name | ForEach-Object { "$($_.Name)/" } + + $choice = $entries | fzf --header="$Prompt [current: $current]" + if(-not $choice) { return $null } + + switch ($choice) + { + "[Use this folder]" { return $current } + "[Create new folder]" { + $name = (Read-Host "New folder name (inside $current)").Trim() + if([string]::IsNullOrWhiteSpace($name)) { continue } + if($name.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0) { Write-Host "Invalid folder name." -ForegroundColor Yellow; continue } + $newPath = Join-Path $current $name + try { New-Item -ItemType Directory -Path $newPath -Force -ErrorAction Stop | Out-Null; $current = $newPath } + catch { Write-Host "Could not create folder: $($_.Exception.Message)" -ForegroundColor Yellow } + continue + } + "[Type path manually]" { $typed = Read-Host "Enter path"; if(-not [string]::IsNullOrWhiteSpace($typed)) { return (ConvertTo-FullFolderPath $typed) }; continue } + ".." { $current = $parent; continue } + default { $current = Join-Path $current ($choice.TrimEnd('/')); continue } + } + } +} diff --git a/Scripts/Private/Start-IntuneManagementTui.ps1 b/Scripts/Private/Start-IntuneManagementTui.ps1 index 229ea77..2d6f5e5 100644 --- a/Scripts/Private/Start-IntuneManagementTui.ps1 +++ b/Scripts/Private/Start-IntuneManagementTui.ps1 @@ -107,49 +107,7 @@ function Select-MenuItem return Show-NumberedMenu -Items $Items -Header $Header -Multi:$Multi } -function Select-FolderPath -{ - param( - [Parameter(Mandatory)] - [string]$Prompt, - [string]$StartPath = (Get-Location).Path - ) - if(-not (Test-FzfAvailable)) - { - return Read-Host $Prompt - } - - $current = if(Test-Path -LiteralPath $StartPath) { (Resolve-Path -LiteralPath $StartPath).Path } else { (Get-Location).Path } - - while($true) - { - $entries = @("[Use this folder]", "[Create new folder]", "[Type path manually]") - $parent = Split-Path -Path $current -Parent - if($parent) { $entries += ".." } - $subdirs = Get-ChildItem -LiteralPath $current -Directory -ErrorAction SilentlyContinue | Sort-Object Name | ForEach-Object { "$($_.Name)/" } - $entries += $subdirs - - $choice = $entries | fzf --header="$Prompt [current: $current]" - if(-not $choice) { return $null } - - switch ($choice) - { - "[Use this folder]" { return $current } - "[Create new folder]" { - $name = (Read-Host "New folder name (inside $current)").Trim() - if([string]::IsNullOrWhiteSpace($name)) { continue } - if($name.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0) { Write-Host "Invalid folder name." -ForegroundColor Yellow; continue } - $newPath = Join-Path $current $name - try { New-Item -ItemType Directory -Path $newPath -Force -ErrorAction Stop | Out-Null; $current = $newPath } - catch { Write-Host "Could not create folder: $($_.Exception.Message)" -ForegroundColor Yellow } - continue - } - "[Type path manually]" { $typed = Read-Host "Enter path"; if(-not [string]::IsNullOrWhiteSpace($typed)) { return $typed }; continue } - ".." { $current = $parent; continue } - default { $current = Join-Path $current ($choice.TrimEnd('/')); continue } - } - } -} +. (Join-Path $PSScriptRoot "Select-FolderPath.ps1") function Read-YesNo { diff --git a/Start-IntuneToolkit.ps1 b/Start-IntuneToolkit.ps1 index 0b9ab06..9385d0e 100644 --- a/Start-IntuneToolkit.ps1 +++ b/Start-IntuneToolkit.ps1 @@ -108,6 +108,7 @@ function Select-MenuItem #endregion $projectRoot = $PSScriptRoot +. (Join-Path $projectRoot "Scripts/Private/Select-FolderPath.ps1") #region Tenant selection function Get-DefaultSettingsPath @@ -330,35 +331,34 @@ $commonParams = @{ # is assigned automatically, so entries can be added or moved without renumbering anything. $menuDefs = @( # Export / Import - "1. Export policies" - "2. Import policies" - "23. Full tenant export (all types + assignments, dated folder)" - "7. Export assignments to CSV/Markdown" - "5. Backup assignments" - "6. Restore assignments" + @{ Id = 1; Label = "Export policies" } + @{ Id = 2; Label = "Import policies" } + @{ Id = 23; Label = "Full tenant export (all types + assignments, dated folder)" } + @{ Id = 7; Label = "Export assignments to CSV/Markdown" } + @{ Id = 5; Label = "Backup assignments" } + @{ Id = 6; Label = "Restore assignments" } # Bulk operations - "3. Bulk app assignment" - "4. Bulk assignment manager (policies)" - "8. Bulk rename policies" - "21. Bulk delete policies" - "24. Bulk scope tags (add / replace / remove / clean up)" - "9. Bulk device operations" + @{ Id = 3; Label = "Bulk app assignment" } + @{ Id = 4; Label = "Bulk assignment manager (policies)" } + @{ Id = 8; Label = "Bulk rename policies" } + @{ Id = 21; Label = "Bulk delete policies" } + @{ Id = 24; Label = "Bulk scope tags (add / replace / remove / clean up)" } + @{ Id = 9; Label = "Bulk device operations" } # Baselines & compliance - "10. Deploy baseline" - "11. Deploy baseline (dry-run / WhatIf)" - "17. Deploy CIS M365 baseline" - "19. Document Conditional Access policies" + @{ Id = 10; Label = "Deploy baseline" } + @{ Id = 11; Label = "Deploy baseline (dry-run / WhatIf)" } + @{ Id = 17; Label = "Deploy CIS M365 baseline" } + @{ Id = 19; Label = "Document Conditional Access policies" } # Reporting - "16. Generate reports" - "20. Export Entra role membership" - "22. Compare two tenant exports (offline)" + @{ Id = 16; Label = "Generate reports" } + @{ Id = 20; Label = "Export Entra role membership" } + @{ Id = 22; Label = "Compare two tenant exports (offline)" } # Tenant & auth admin - "12. Initialize auth (one-time setup)" - "13. Refresh tenant names" - "18. Rotate app secret" - "14. Delete local tenant auth only" - "15. Delete tenant auth and app registration" - "0. Exit" + @{ Id = 12; Label = "Initialize auth (one-time setup)" } + @{ Id = 13; Label = "Refresh tenant names" } + @{ Id = 18; Label = "Rotate app secret" } + @{ Id = 14; Label = "Delete local tenant auth only" } + @{ Id = 15; Label = "Delete tenant auth and app registration" } ) $menuIdByNumber = @{} $menuItems = @() @@ -482,18 +482,18 @@ while($true) $exportPath = $null if($dataSource -like "*fresh*") { - $exportPath = Read-Host "Export path (where to save fresh data)" + $exportPath = Select-FolderPath -Prompt "Export path (where to save fresh data)" if([string]::IsNullOrWhiteSpace($exportPath)) { Write-Host "Required." -ForegroundColor Red; continue } $backupRoot = $exportPath } else { - $backupRoot = Read-Host "Backup root path" + $backupRoot = Select-FolderPath -Prompt "Backup root path" if([string]::IsNullOrWhiteSpace($backupRoot)) { Write-Host "Required." -ForegroundColor Red; continue } if(-not (Test-Path $backupRoot)) { Write-Host "Path not found: $backupRoot" -ForegroundColor Red; continue } } - $outputDir = Read-Host "Output directory for reports" + $outputDir = Select-FolderPath -Prompt "Output directory for reports" if([string]::IsNullOrWhiteSpace($outputDir)) { Write-Host "Required." -ForegroundColor Red; continue } $includeAssignments = $false @@ -528,9 +528,8 @@ while($true) { $defaultRoot = Get-LauncherSetting -SettingsPath $settingsPath -Name "FullExportRoot" if([string]::IsNullOrWhiteSpace($defaultRoot)) { $defaultRoot = Join-Path $HOME "Local/IntuneExports" } - $root = Read-Host "Export root folder (Enter = $defaultRoot)" - if([string]::IsNullOrWhiteSpace($root)) { $root = $defaultRoot } - $root = [IO.Path]::GetFullPath(($root.Trim().Trim('"',"'") -replace '^~', $HOME)) + $root = Select-FolderPath -Prompt "Export root folder" -StartPath $defaultRoot -Default $defaultRoot + if(-not $root) { continue } Set-LauncherSetting -SettingsPath $settingsPath -Name "FullExportRoot" -Value $root $tenantLabel = if($currentTenant -and $currentTenant.TenantName) { $currentTenant.TenantName } else { $TenantId } @@ -561,9 +560,10 @@ while($true) { $prevPath = if($prev) { $prev.FullName } else { $null } $hint = if($prevPath) { "Enter = $($prev.Name)" } else { "path to an earlier export, Enter to skip" } - $ans = Read-Host "`nCompare with an earlier export to see drift? ($hint, n = skip)" + $ans = Read-Host "`nCompare with an earlier export to see drift? ($hint, n = skip, b = browse)" if($ans -like 'n') { $prevPath = $null } - elseif(-not [string]::IsNullOrWhiteSpace($ans)) { $prevPath = [IO.Path]::GetFullPath(($ans.Trim().Trim('"',"'") -replace '^~', $HOME)) } + elseif($ans -like 'b') { $prevPath = Select-FolderPath -Prompt "Earlier export to compare with" -StartPath $root } + elseif(-not [string]::IsNullOrWhiteSpace($ans)) { $prevPath = ConvertTo-FullFolderPath $ans } if($prevPath -and (Test-Path -LiteralPath $prevPath -PathType Container)) { $prevName = Split-Path $prevPath -Leaf @@ -590,21 +590,22 @@ while($true) $sides = @() foreach($side in "A","B") { - $root = Read-Host "Export folder of tenant $side" + $browseStart = Get-LauncherSetting -SettingsPath $settingsPath -Name "FullExportRoot" + if([string]::IsNullOrWhiteSpace($browseStart)) { $browseStart = Join-Path $HOME "Local/IntuneExports" } + $root = Select-FolderPath -Prompt "Export folder of tenant $side" -StartPath $browseStart if([string]::IsNullOrWhiteSpace($root)) { Write-Host "Required." -ForegroundColor Red; $sides = $null; break } - $root = [IO.Path]::GetFullPath(($root.Trim().Trim('"',"'") -replace '^~', $HOME)) if(-not (Test-Path -LiteralPath $root -PathType Container)) { Write-Host "Folder not found: $root" -ForegroundColor Red; $sides = $null; break } $defaultLabel = Split-Path $root -Leaf $label = Read-Host "Label for tenant $side (default: $defaultLabel)" if([string]::IsNullOrWhiteSpace($label)) { $label = $defaultLabel } $strip = Read-Host "Name prefix regex to strip for tenant $side, e.g. ^SSD\s*-\s* (Enter for none)" + $browseStart = Split-Path $root -Parent $sides += ,@($root, $label, $strip) } if(-not $sides) { continue } - $outputDir = Read-Host "Output directory for the comparison report" + $outputDir = Select-FolderPath -Prompt "Output directory for the comparison report" -StartPath $browseStart if([string]::IsNullOrWhiteSpace($outputDir)) { Write-Host "Required." -ForegroundColor Red; continue } - $outputDir = [IO.Path]::GetFullPath(($outputDir.Trim().Trim('"',"'") -replace '^~', $HOME)) $pyArgs = @( (Join-Path $projectRoot "Scripts/Compare-Tenants.py"),