I have been working on a script that will set DCU to download, install and verify no matter what the current setting is.
In the update settings, a few behaviors are observed:
- Notify: Deletes AutomationMode if present
- Download updates: Creates AutomationMode with a value of ScanDownloadNotify
- Download and install updates: Creates AutomationMode with a value of ScanDownloadApplyNotify
Location of the key:
- HKLM:\SOFTWARE\DELL\UpdateService\Clients\CommandUpdate\Preferences\Settings\Schedule\AutomationMode
The remediation code works perfect in Visual Studio Code. However, the evaluation code will only show the write-output and not push to the remediation code. Could someone shine some light on this?
Evaluation Code
$regPath = 'HKLM:\SOFTWARE\DELL\UpdateService\Clients\CommandUpdate\Preferences\Settings\Schedule'
$automationMode = $null
Try {
$automationMode = Get-ItemPropertyValue -Path $regPath -Name "AutomationMode"
}
Catch {
Write-Output "Error retrieving AutomationMode property: $_"
}
Finally {
if ($automationMode -eq 'ScanDownloadApplyNotify') {
Write-Output 'The value of AutomationMode is currently ScanDownloadApplyNotify. No action taken.'
Exit 0
}
elseif ($automationMode -eq 'ScanDownloadNotify') {
Write-Output 'The value of AutomationMode is currently ScanDownloadNotify. Setting to ScanDownloadApplyNotify.'
Exit 1
}
elseif ($automationMode -eq $null) {
Write-Output 'The key does not exist, adding value.'
Exit 1
}
}
Remediation Code
$regPath = 'HKLM:\SOFTWARE\DELL\UpdateService\Clients\CommandUpdate\Preferences\Settings\Schedule'
$automationMode = $null
Try {
$automationMode = Get-ItemPropertyValue -Path $regPath -Name "AutomationMode"
}
Catch {
Write-Output "Error retrieving AutomationMode property: $_"
}
Finally {
if ($automationMode -eq 'ScanDownloadApplyNotify') {
Write-Output 'The value of AutomationMode is currently ScanDownloadApplyNotify. No action taken.'
}
elseif ($automationMode -eq 'ScanDownloadNotify') {
Write-Output 'The value of AutomationMode is currently ScanDownloadNotify. Setting to ScanDownloadApplyNotify.'
Set-ItemProperty -Path $regPath -Name "AutomationMode" -Value 'ScanDownloadApplyNotify'
}
elseif ($automationMode -eq $null) {
Write-Output 'The key does not exist, adding value.'
New-ItemProperty -Path $regPath -Name "AutomationMode" -Value 'ScanDownloadApplyNotify' -PropertyType String
}
}