Created
April 12, 2018 19:42
-
-
Save dbaghdanov/5594cad602bb37e535103092929a484c to your computer and use it in GitHub Desktop.
Updates a remote server registry to enable .NET to use: TLS 1.0, 1.1, 1.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([Parameter(Position=0)][String[]] $Hosts, [PSCredential] $Credential) | |
Function Get-TlsVersions{ | |
Param($Hosts, $Credential) | |
if($Credential -eq $null){ | |
$Credential = (Get-Credential) | |
} | |
$val = (Invoke-Command -ComputerName $Hosts -Credential $Credential -ScriptBlock {[Net.ServicePointManager]::SecurityProtocol}).Value.split(",").trim() | |
write-output $val | |
} | |
Function Is-Tls12-Enabled{ | |
Param($Hosts, $Credential) | |
if($Credential -eq $null){ | |
$Credential = (Get-Credential) | |
} | |
(Get-TlsVersions $Hosts $Credential) -Contains "Tls12" | |
} | |
Function Enable-Tls12{ | |
Param($Hosts, $Credential) | |
if($Credential -eq $null){ | |
$Credential = (Get-Credential) | |
} | |
Invoke-Command -ComputerName $Hosts -Credential $Credential -ScriptBlock {Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord} | |
Invoke-Command -ComputerName $Hosts -Credential $Credential -ScriptBlock {Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord} | |
} | |
Function Disable-Tls12{ | |
Param($Hosts, $Credential) | |
if($Credential -eq $null){ | |
$Credential = (Get-Credential) | |
} | |
Invoke-Command -ComputerName $Hosts -Credential $Credential -ScriptBlock {Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '0' -Type DWord} | |
Invoke-Command -ComputerName $Hosts -Credential $Credential -ScriptBlock {Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '0' -Type DWord} | |
} | |
if($Hosts -eq $null -Or $Hosts -eq ""){ | |
Write-Host "No Hosts computer specified" | |
Return | |
} | |
if( $Credential -eq $null -Or $Credential -eq ""){ | |
$Credential = (Get-Credential) | |
} | |
foreach($i in $Hosts){ | |
if( (Is-Tls12-Enabled $i $Credential) -eq $true){ | |
Write-Host "[$i] - TLS 1.2 is already enabled." | |
Continue | |
} | |
else{ | |
Write-Host "Enabling TLS 1.2 for the .NET Framework..." | |
Enable-Tls12 $i $Credential | |
Write-Host "--- TLS Versions ---" | |
Get-TlsVersions $i $Credential | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment