0

I'm currently trying to add a registry key to mutiple registry folders. However becasue you can't wildcard registry keys via group policy I'm using a ps1 script to add these keys. Essentially I would like to add a REG_Binary key with the hex value of 00 00 00 00 in this location: HKCU:\SOFTWARE\Microsoft\Office\15.0\Outlook\Profiles\name of outlook profile\c02ebc5353d9cd11975200aa004ae40e.

I have the code that adds this key on one profile using one line of PS. This is:

$path = "HKCU:\SOFTWARE\Microsoft\Office\15.0\Outlook\Profiles\Name of Outlook Profile\c02ebc5353d9cd11975200aa004ae40e"

New-ItemProperty -Path $path -Name 00030354 -PropertyType Binary -Value ([byte[]](0x00,0x00,0x00,0x00)) -Force

This works perfectly, however I need to do this on all folders in the profiles directory. I can find out all the profile names in this string via this command:

$Profilelist = get-childItem "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles\*" | select name

How can I add the value "\c02ebc5353d9cd11975200aa004ae40e" to each line of this array/list?

After adding this I will be able to use a for each command to add the key.

If anyone knows a better way I'm open to other ideas!

Thanks in advance! :)

2 Answers 2

1

The easiest way IMO is with a calculated property:

$Profilelist = get-childItem "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles\*" | select @{n='extendedname'; e={'{0}\c02ebc5353d9cd11975200aa004ae40e' -f $_.Name.Replace('HKEY_CURRENT_USER\', 'HKCU:\'}}
Sign up to request clarification or add additional context in comments.

1 Comment

This would work perfectly, however because the get child-item changes the start from HKCU:\ to HKEY_CURRENT_USER\ I get the error message New-ItemProperty : Cannot find path 'C:\WINDOWS\system32\HKEY_CURRENT_USER\Software ... etc. Any ideas on how to change the start of the string so this command would work? Thanks
1

Try:

Get-ChildItem -Path "HKCU:\SOFTWARE\Microsoft\Office\15.0\Outlook\Profiles" | ForEach-Object {
    $path = Join-Path $_.Name "c02ebc5353d9cd11975200aa004ae40e"
    #Create key if missing
    if(-not (Test-Path $path)) { New-Item -ItemType RegistryKey -Path $path }
    New-ItemProperty -Path $path -Name 00030354 -PropertyType Binary -Value ([byte[]](0x00,0x00,0x00,0x00)) -Force
}

3 Comments

This would work perfectly, however because the get child-item changes the start from HKCU:\ to HKEY_CURRENT_USER\ I get the error message New-ItemProperty : Cannot find path 'C:\WINDOWS\system32\HKEY_CURRENT_USER\Software ... etc. Any ideas on how to change the start of the string so this command would work? Thanks
@user3290171 just replace it.
The problem is that you need to create the key first. Updated now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.