Powershell pipe modified registry value

Viewed 40

(How) can I pipe this (without using the variables)?

$regPath="HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
$regProp="AppsUseLightTheme";

$toggledDarkMode = (Get-ItemProperty $regPath $regProp).$regProp -bxor 1
Set-ItemProperty $regPath $regProp $toggledDarkMode;

Something like:

Get-ItemProperty ... | Set-ItemProperty -value ($_ -bxor 1) ...
1 Answers

Use ForEach-Object to wrap the call to Set-ItemProperty:

Get-ItemPropertyValue -Path $regPath -Name $regProp |ForEach-Object {
    Set-ItemProperty -Path $regPath -Name $regProp -Value ($_ -bxor 1)
}
Related