david62277

redirections.xml builder

Apr 8th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function buildlist($b, $p)
  2. {
  3.     if ($b -eq "Chrome")
  4.     {
  5.         $folders = "Cache", "Cached Theme Image", "JumpListIcons", "JumpListIconsOld", "Local Storage", "Storage", "GPUCache", "Sync Data", "blob_storage", "IndexedDB", "Application Cache", "Code Cache" #,"Session Storage"
  6.         foreach ($folder in $folders)
  7.         {
  8.             if (test-path (Join-Path $p $folder))
  9.             {
  10.                 ((join-path $p $folder) -split "$env:username\\")[1]
  11.             }
  12.         }
  13.     }
  14.     else
  15.     {
  16.         $folders = "cache2", "jumpListCache", "OfflineCache", "startupCache", "thumbnails"
  17.         foreach ($folder in $folders)
  18.         {
  19.             if (test-path (Join-Path $p $folder))
  20.             {
  21.                 ((join-path $p $folder) -split "$env:username\\")[1]
  22.             }
  23.         }
  24.     }
  25.    
  26. }
  27.  
  28. $redirection = "$env:localappdata\FSLogix\Redirections.xml"
  29. $firefoxprofiles = (gci "$env:localappdata\mozilla\firefox\Profiles" | ?{ $_.psiscontainer }).fullname
  30. $firefoxexcludes = @()
  31. $chromeexcludes = @()
  32. foreach ($fprof in $firefoxprofiles)
  33. {
  34.     $firefoxexcludes += buildlist -b firefox -p $fprof
  35. }
  36. $googleprofiles = (gci "$env:localappdata\Google\Chrome\User Data" | ?{ $_.psiscontainer -and ($_.name -eq "default" -or $_.name -like "profile*") }).fullname
  37. foreach ($gprof in $googleprofiles)
  38. {
  39.     $chromeexcludes = buildlist -b chrome -p $gprof
  40. }
  41. $onenotecaches = (gci $env:LOCALAPPDATA\Microsoft\Onenote -Recurse  -ea SilentlyContinue| ?{ $_.psiscontainer -and $_.name -like "*cache" }).fullname | %{
  42.     ($_ -split "$env:username\\")[1]
  43. }
  44.  
  45. $template = "<?xml version=`"1.0`"?>
  46. <FrxProfileFolderRedirection ExcludeCommonFolders=`"128`">
  47.     <Includes>
  48.         <Include>AppData\Roaming\Microsoft\Excel\XLSTART\</Include>
  49.        <Include>AppData\Roaming\Microsoft\Word\STARTUP</Include>
  50.     </Includes>
  51.     <Excludes>
  52.         <Exclude Copy=`"0`">AppData\Roaming\Microsoft\Excel\</Exclude>
  53.        <Exclude Copy=`"0`">AppData\Roaming\Microsoft\Word\</Exclude>"
  54. $end = "`r`n</Excludes>
  55. </FrxProfileFolderRedirection>"
  56. if ($firefoxexcludes)
  57. {
  58.     foreach ($f in $firefoxexcludes)
  59.     {
  60.         $template += "`r`n<Exclude Copy=`"0`">" + $f + "</Exclude>"
  61.     }
  62. }
  63. if ($chromeexcludes)
  64. {
  65.     foreach ($c in $chromeexcludes)
  66.     {
  67.         $template += "`r`n<Exclude Copy=`"0`">" + $c + "</Exclude>"
  68.     }
  69. }
  70. if ($onenotecaches)
  71. {
  72.     foreach ($o in $onenotecaches)
  73.     {
  74.         $template += "`r`n<Exclude Copy=`"0`">" + $o + "</Exclude>"
  75.     }
  76. }
  77. $template += $end
  78. $template | out-file $redirection -force
Advertisement
Add Comment
Please, Sign In to add comment