Skip to content

Instantly share code, notes, and snippets.

@jetersen
Last active May 30, 2023 08:17
Show Gist options
  • Save jetersen/0ac37e3f684947889d53cccb7391a9c5 to your computer and use it in GitHub Desktop.
Save jetersen/0ac37e3f684947889d53cccb7391a9c5 to your computer and use it in GitHub Desktop.
Enable TLS 1.2 for .NET application including Windows PowerShell and .NET 45 and below
#requires -runasadministrator
# set strong cryptography on 64 bit .Net Framework
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord
# set strong cryptography on 32 bit .Net Framework
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions' -Value '1' -Type DWord
#requires -runasadministrator
# revert strong cryptography on 64 bit .Net Framework
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SchUseStrongCrypto'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions'
# revert strong cryptography on 32 bit .Net Framework
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SchUseStrongCrypto'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' -Name 'SystemDefaultTlsVersions'
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SystemDefaultTlsVersions'
@jetersen
Copy link
Author

jetersen commented May 30, 2023

Here is an array version of it:

$properties = @{
    'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v2.0.50727' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
    'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
    'HKLM:\SOFTWARE\Microsoft\.NETFramework\v2.0.50727' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
    'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' = @('SchUseStrongCrypto', 'SystemDefaultTlsVersions')
}

foreach ($property in $properties.GetEnumerator()) {
    $path = $property.Key
    $names = $property.Value
    foreach ($name in $names) {
        Set-ItemProperty -Path $path -Name $name -Value 1 -ErrorAction SilentlyContinue
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment