Skip to content

Instantly share code, notes, and snippets.

@dafzor
Created October 8, 2022 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dafzor/5656bb96609befdcb7ac5b064f2031ec to your computer and use it in GitHub Desktop.
Save dafzor/5656bb96609befdcb7ac5b064f2031ec to your computer and use it in GitHub Desktop.
Flattens start menu to remove all folders
$usr_sm_folder = "$($env:AppData)\Microsoft\Windows\Start Menu\Programs"
$sys_sm_folder = "$($env:ProgramData)\Microsoft\Windows\Start Menu\Programs"
$folder_exclusions = @(
'Administrative Tools',
'Startup',
'Steam'
)
function Remove-ShortcutFolder ($folder, $exclusions) {
Write-Output "Flattening folder: '$folder'"
# recursivly flattens and moves the content of all subdirectories
foreach ($d in Get-ChildItem $folder -Directory -Exclude $exclusions) {
Remove-ShortcutFolder $d
Move-Item $d\*.* $folder -Force
if ((Get-ChildItem $d -Directory).Count -lt 1) {
Write-Output "Removing empty folder: '$d'"
Remove-Item $d -Force
}
}
}
Remove-ShortcutFolder $usr_sm_folder $folder_exclusions
Remove-ShortcutFolder $sys_sm_folder $folder_exclusions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment