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