Improve error handling and logging in common.vm and fix registry errors in debloat.vm#1482
Improve error handling and logging in common.vm and fix registry errors in debloat.vm#1482
Conversation
Refactors to use a new function. This change eliminates code duplication between the and sections, making the script more maintainable.
Refactored the function to include granular blocks within each processing loop. This prevents a single configuration error, such as an invalid registry type, from halting the entire script. The change ensures that the script continues to process subsequent items in the XML configuration file, while still logging a specific error message for any individual item that fails.
| if ($config.config."registry-items"."registry-item") { | ||
| VM-Write-Log "INFO" "Processing registry items..." | ||
| $config.config."registry-items"."registry-item" | ForEach-Object { | ||
| try { |
There was a problem hiding this comment.
I don't like the try-catch duplication, as we have a try-catch already inside the function, that can cause the Failed to update registry item error message to be duplicated. The try-catch inside the called function does not apply if the arguments for the function are wrong (as it happened with the provided type argument). Should we remove the try-catch inside the function and leave it here?
Also, I think VM-Update-Registry-Value continues to fail in Windows 11 here is because Set-ItemProperty does not have a Type argument.The extra argument was ignored in Windows 10, but causes an error in Windows 11.
Set-ItemProperty -Path $path -Name $value -Value $validatedData -Type $type -Force | Out-Null
| <registry-item name="Disable Microsoft Connectivity Test (msftconnecttest.com)" path="HKLM:\SYSTEM\CurrentControlSet\services\NlaSvc\Parameters\Internet" value="EnableActiveProbing" type="DWord" data="0" /> | ||
| <registry-item name="Disable Resetbase" path="HKLM\Software\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" value="DisableResetbase" type="REG_DWORD" data="0"/> | ||
| <registry-item name="Disable LetAppsActivateWithVoice" path="HKLM\SOFTWARE\Policies\Microsoft\Windows\AppPrivacy" value="LetAppsActivateWithVoice" type="REG_DWORD" data="2"/> | ||
| <registry-item name="Disable Resetbase" path="HKLM\Software\Microsoft\Windows\CurrentVersion\SideBySide\Configuration" value="DisableResetbase" type="DWord" data="0"/> |
There was a problem hiding this comment.
[question] even correcting the code, it seems all these registry configurations are not applied in my Windows 11 VM. Are they applied for you @emtuls or are they only Windows 11 specific and we could remove them here?
Created a function to handle start menu cleanup in
debloat.vmto eliminate code duplication making the script more maintainable, addressing #1462 (review).Fixed errors in
win11.xmlandwin11arm.xmlregistry key modifications and refactored theVM-Apply-Configurationfunction to include granular blocks within each processing loop. This prevents a single configuration error, such as an invalid registry type, from halting the entire script, closing #1479Fixed logging issues with
common.vm, closing #1478