From 963245b96763ebf62135f223fc1240dd5e11949f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 18 Jul 2023 20:51:11 +0200 Subject: [PATCH] Remove ads from Windows --- scripts/Windows/Collections/Personal.ps1 | 2 +- .../Windows/Config/Windows/InstallUser.ps1 | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 scripts/Windows/Config/Windows/InstallUser.ps1 diff --git a/scripts/Windows/Collections/Personal.ps1 b/scripts/Windows/Collections/Personal.ps1 index 34f35ef0..9a029bc7 100644 --- a/scripts/Windows/Collections/Personal.ps1 +++ b/scripts/Windows/Collections/Personal.ps1 @@ -33,8 +33,8 @@ function Restore-PersonalApps([Context] $context) { Install-PersonalDrivers $context; } + . "$PSScriptRoot/../Config/Windows/InstallUser.ps1"; . "$PSScriptRoot/../Software/chocolatey/Install.ps1"; - $context.RemoveDesktopIcon("Microsoft Edge"); # Backed up applications Restore-Git $context; diff --git a/scripts/Windows/Config/Windows/InstallUser.ps1 b/scripts/Windows/Config/Windows/InstallUser.ps1 new file mode 100644 index 00000000..48f4d592 --- /dev/null +++ b/scripts/Windows/Config/Windows/InstallUser.ps1 @@ -0,0 +1,49 @@ +#!/bin/pwsh +param($context) + +. "$PSScriptRoot/../../Scripts/Context.ps1"; + +[Context] $context = $context; +$tempDir = $context.GetTempDirectory(); +$startLayoutFile = "start.json"; +Push-Location "$tempDir"; + +Write-Host "Configuring Windows for Users"; +Write-Information "Remove MSEdge Icon"; +$context.RemoveDesktopIcon("Microsoft Edge"); + +Write-Information "Remove ads from pinned apps"; +Export-StartLayout $startLayoutFile; + +$startLayout = Get-Content "$startLayoutFile" | ConvertFrom-Json; +[System.Collections.Generic.List[System.Object]] $removalQueue = @(); + +foreach ($pinnedItem in $startLayout.pinnedList) { + if ( + ($pinnedItem.desktopAppLink -like "*Microsoft Edge*") -or + [System.Linq.Enumerable]::Any( + @( + "*MicrosoftOfficeHub*", + "*SpotifyMusic*", + "*WhatsApp*", + "*PrimeVideo*", + "*Netflix*", + "*Instagram*", + "*Chipchamp*", + "*Facebook*"), + { + param($pattern) + return $pinnedItem.packageAppId -like "$pattern"; + })) { + $removalQueue += @($pinnedItem); + } +} + +foreach ($item in $removalQueue) { + $startLayout.pinnedList.Remove($item); +} + +$startLayout | ConvertTo-Json | Set-Content $startLayoutFile; + +Pop-Location "$tempDir"; +Remove-Item -Recurse "$tempDir";