Pickle
Pickle

Reputation: 1124

Powershell import registry key in code

I'm looking to import the below registry key without actually importing the .reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Cirrato]
"postInstallExecTimeout"=dword:0000001e
"ConfigApplyAllSettingsForModels"=""
"ConfigApplyAllSettingsForQueueNames"=""
"ConfigApplyPreferencesOnlyForQueueNames"=""
"OURestrictFailureCaption"=""
"OURestrictFailureText"=""

Is it possible to import this key in-line? I can't find any resources demonstrating how to add a registry key with multiple values like this.

Upvotes: 0

Views: 5840

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200473

You can easily create a registry key from scratch like this:

$path = 'HKLM:\SOFTWARE\Cirrato'
$path = 'HKCU:\SOFTWARE\foo'

New-Item -Path $path -Force | Out-Null

Set-ItemProperty -Path $path -Name 'postInstallExecTimeout' -Value 30
Set-ItemProperty -Path $path -Name 'ConfigApplyAllSettingsForModels' -Value ''
Set-ItemProperty -Path $path -Name 'ConfigApplyAllSettingsForQueueNames' -Value ''
Set-ItemProperty -Path $path -Name 'ConfigApplyPreferencesOnlyForQueueNames' -Value ''
Set-ItemProperty -Path $path -Name 'OURestrictFailureCaption' -Value ''
Set-ItemProperty -Path $path -Name 'OURestrictFailureText' -Value ''

The registry entries will normally be created with the appropriate type for the input value (REG_DWORD for integers, REG_SZ for strings). If not you can specify the type via the -Type parameter.

Upvotes: 1

Related Questions