I have following power-shell function to add registry items to the registry. But it doesn’t execute and I can’t see any errors. I am newbie to power-shell. Can’t figure it out why it’s not working. Any ideas?
function Write-Log {
Param (
[Parameter(Mandatory=$true)]
[string]$Message,
[Parameter(Mandatory=$false)]
[string]$Level = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp [$Level] $Message"
Add-Content -Path $logPath -Value $logEntry
}
function Update-TLSRegistry {
Write-Log "Enabling TLS1.2"
try {
$ErrorActionPreference = "Stop"
$HKCUTLSClient = "HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.2Client"
$HKCUTLSServer = "HKLM:SYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.2Server"
New-Item $HKCUTLSClient -Force
New-ItemProperty -Path $HKCUTLSClient –PropertyType "DWORD" -Name "DisabledByDefault" -Value "0"
New-ItemProperty -Path $HKCUTLSClient -PropertyType "DWORD" -Name "Enabled" -Value "1"
New-Item $HKCUTLSServer -Force
New-ItemProperty -Path $HKCUTLSServer –PropertyType "DWORD" -Name "DisabledByDefault" -Value "0"
New-ItemProperty -Path $HKCUTLSServer –PropertyType "DWORD" -Name "Enabled" -Value "1"
Write-Log "Successfully enabled TLS1.2"
} catch {
Write-Log "Failed to enable TLS1.2: $_"
throw
}
}
# call the function
Update-TLSRegistry