I have a Registration Entries (.reg) file, and I wanted to convert it to a PowerShell script.
On my way, I encountered this value: hex:00.
Here is the registry key & value that I want to set:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{042D8A51-5878-4000-9C10-C04AFF122A1F}"
"Triggers"=hex:00
How do I set this Hex value using Set-ItemPropery?
When you use Set-ItemProperty to target registry paths, the cmdlet supports a dynamic parameter named -Type that accepts a Microsoft.Win32.RegistryValueKind value, which specifies the value's data type.
The presence of hex: in your *.reg file implies binary (raw bytes) as the data type; therefore:
Binary to -Type-Value; to produce the equivalent of hex:00 - i.e. a single byte with value 0x0 - use -Value 0x0 (to pass multiple bytes, separate them with , e.g.: -Value 0x0, 0x1):Set-ItemProperty -Type Binary -Value 0x0 -Name Triggers -LiteralPath 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{042D8A51-5878-4000-9C10-C04AFF122A1F}'
Also note the registry:: prefix to the registry key path, which is required to identify the path as a registry path (in a context-independent manner).
Alternatively, replace registry::HKEY_LOCAL_MACHINE with HKLM:, to base the path on the equivalent PowerShell-specific drive instead. (The other predefined registry drive is HKCU:, which is equivalent to registry::HKEY_CURRENT_USER; Get-PSDrive-PSProvider registry shows all registry-based drives).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With