Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.07k forks source link

optimize Enable/DisableAppSuggestions code. #160

Closed scruel closed 6 years ago

scruel commented 6 years ago

Replace all the code for 'SubscribedContent' like keys in registry with the loop code.

Disassembler0 commented 6 years ago

Sorry, this doesn't make any sense.

1) 4 out of the 7 values don't exist after installation. You can't loop through something you don't have.

2) The values which don't originally exist aren't just set to 1 in EnableAppSuggestions but removed altogether to restore the original state as completely as possible.

3) As per FAQ:

Q: Why are there repeated pieces of code throughout some functions? A: So you can directly take a function block or a line from within a function and use it elsewhere, without elaborating on any dependencies.

This applies also for the individual registry modification. Same reason why eg. bloatware removal tweaks don't use loops.

scruel commented 6 years ago

@Disassembler0 All right...But I think you haven't reviewed all parts of my code?

the following line of code I added in, may answer your 1, 2 questions above? If($_.Name -Match 'SubscribedContent') {

Also, I've tested it from 1703 to 1809 and works fine for myself.

Disassembler0 commented 6 years ago
(Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' -ErrorAction SilentlyContinue).PSObject.Properties | ForEach-Object {
    If ($_.Name -Match 'SubscribedContent') {
        Write-Output $_.Name
    }
}

on clean installation of 1809 prints

SubscribedContent-338389Enabled
SubscribedContent-338388Enabled
SubscribedContent-353696Enabled

Therefore the 4 keys which don't exist won't get set.

ghost commented 6 years ago

I noticed that SubscribedContent items could be pre-guessed by looking at the ContentDeliveryManager\Subscriptions subkeys, so these keys might be looped as their numbers match those SubscribedContent items...mostly. Unfortunately there seem to be unused numbers and worse, I also noticed one extra SubscribedContent* that is not covered.

As per FAQ

I wouldn't always stick with this rule, especially for potentially dynamic situation. :) As you didn't for example in DisableBackgroundApps. ;)

Disassembler0 commented 6 years ago

...so these keys might be looped...

How would you do the revert tweak for this which would restore the exact defaults?

...As you didn't for example in DisableBackgroundApps

That's just an ugly workaround because the toggle to disable them all in one go is broken in Windows.