Reputation: 1
@{
Keys = @(
@{
Id = "DTBI014-IE11"
Task = "Turn off Encryption Support must be enabled."
Path = "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
Name = "SecureProtocols"
Value = 2560
}
@{
Id = "DTBI015-IE11"
Task = "The Internet Explorer warning about certificate address mismatch must be enforced."
Path = "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
Name = "WarnOnBadCertRecving"
Value = 1
}
@{
Id = "DTBI018-IE11"
Task = "Check for publishers certificate revocation must be enforced."
Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing"
Name = "State"
Value = 146432
}
)
} ForEach ($Key in $Keys) { Write-Output $Task New-ItemProperty -Path $Path -Name $Name --PropertyType Dword -Value $Value -Force }
Upvotes: 0
Views: 225
Reputation: 61198
As commented, you are using undefined variables like $Path
, $Name
etc. instead of the properties .Path
, .Name
etc.
To test if the key exists before trying to add a value, you can use the Test-Path
cmdlet:
$Keys =
@{
Id = "DTBI014-IE11"
Task = "Turn off Encryption Support must be enabled."
Path = "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
Name = "SecureProtocols"
Value = 2560
},
@{
Id = "DTBI015-IE11"
Task = "The Internet Explorer warning about certificate address mismatch must be enforced."
Path = "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings"
Name = "WarnOnBadCertRecving"
Value = 1
},
@{
Id = "DTBI018-IE11"
Task = "Check for publishers certificate revocation must be enforced."
Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\WinTrust\Trust Providers\Software Publishing"
Name = "State"
Value = 146432
}
foreach ($item in $Keys) {
Write-Output $item.Task
if (!(Test-Path $item.Path)) {
# if the key does not already exist, create it
New-Item -Path $item.Path -Force | Out-Null
}
# now add the new property
New-ItemProperty -Path $item.Path -Name $item.Name -PropertyType Dword -Value $item.Value -Force -WhatIf | Out-Null
}
Upvotes: 0