Refactor ad removal

This commit is contained in:
Manuel Thalmann 2023-07-18 23:46:03 +02:00
parent d537ba87a5
commit 70a757cdcb

View file

@ -30,9 +30,10 @@ $context.ProcessDefaultUserKey($action);
Write-Information "Remove ads from pinned apps";
Export-StartLayout $startLayoutFile;
$startLayout = Get-Content "$startLayoutFile" | ConvertFrom-Json;
$startLayout = Get-Content "$startLayoutFile" | ConvertFrom-Json
$originalProperty = "pinnedList";
$startLayout.pinnedList = $startLayout.pinnedList | Where-Object {
$newLayout = $startLayout[$originalProperty] | Where-Object {
return -not (
($_.desktopAppLink -like "*Microsoft Edge*") -or
[System.Linq.Enumerable]::Any(
@ -52,8 +53,10 @@ $startLayout.pinnedList = $startLayout.pinnedList | Where-Object {
}));
}
$startLayout | ConvertTo-Json -Compress | Set-Content $startLayoutFile;
Import-StartLayout $startLayoutFile "$env:SystemDrive";
$startLayout.PSObject.Properties.Remove($originalProperty);
$startLayout | Add-Member -NotePropertyName "primaryOEMPins" -NotePropertyValue $newLayout;
$startLayout | ConvertTo-Json -Compress | Set-Content "$env:SystemDrive\Users\Default\AppData\Local\Microsoft\Windows\Shell";
Pop-Location;
Remove-Item -Recurse "$tempDir";