0

I have multiple sites that I want to add to HKCU:Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ I would rather do this with a Foreach loop so I don't have to run a single script individually.

if (-not (Test-Path -Path 'HKCU:Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\123.abc'))

{

New-Item -Path 'HKCU:Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\123.abc'

Set-ItemProperty -Path 'HKCU:Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\123.abc' -Name https -Value 2 -Type DWord

}

I cannot seem to figure out the ForEach part

$domains = '123.abc', 'xyz.abc', 'abc.abc'

ForEach ($domains in $domains) {

.....

here is where I'm a little lost.

1 Answer 1

0

You could do something like this:

$domains = '123.abc', 'xyz.abc', 'abc.abc'

foreach ($domain in $domains){

    $RegKey = 'HKCU:Software\Microsoft\Windows\CurrentVersion\Internet 
    Settings\ZoneMap\Domains\' + $domain

    if (-not(Test-Path $RegKey)){

        New-Item -Path $RegKey 
        Set-ItemProperty -Path $RegKey -Name https -Value 2 -Type DWord
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.