Public/Network/Set-TlsLevel.ps1

function Set-TlsLevel {
  [CmdletBinding( SupportsShouldProcess = $false )]
  [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')]
  param (
    [Parameter(Mandatory, ParameterSetName = 'Set')]
    [Switch]$Tls12,

    [Parameter(Mandatory, ParameterSetName = 'Revert')]
    [Switch]$Revert
  )

  begin {
    switch ($PSCmdlet.ParameterSetName) {
      "Set" {
        $Script:OriginalTlsSettings = [Net.ServicePointManager]::SecurityProtocol

        [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
      }
      "Revert" {
        if ($Script:OriginalTlsSettings) {
          [Net.ServicePointManager]::SecurityProtocol = $Script:OriginalTlsSettings
        }
      }
    }
  }
}