PowerShell: How to get Windows Remote Management Version (WinRM)

# Using below function you can get Windows Remote Management Version (WinRM)

function Get-WinRMVersion {

 PARAM (

  [Parameter(Mandatory = $false,

   ValueFromPipeline = $true,

   ValueFromPipelineByPropertyName = $true)]

  [Alias('HostNames')]

  [String[]]$ComputerNames = "."

 )

 BEGIN {

  if ($ComputerNames -contains ".") {

   $ComputerNames = $ComputerNames.Replace(".", ($env:COMPUTERNAME).ToLower())

  }

  

  function New-HashTable {

   $result = [ordered]@{

    ComputerName = $testWSMan.ComputerName

    WinRMVersion = $testWSMan.WinRMVersion

   }

   New-Object psobject -Property $result

  }

 }

 PROCESS {

  foreach ($computerName in $ComputerNames) {

   try {

    $testWSMan = Test-WSMan -ComputerName $computerName -ErrorAction Stop | Select-Object @{Label = "ComputerName"; Expression = { $computerName } }, `

    @{Label = "WinRMVersion"; Expression = { ($_.ProductVersion -split (':'))[-1].trim() } }

   }

   catch {

    if ($_.Exception.Message -like "*WinRM cannot complete the operation.*") {

     $testWSMan = @{

      ComputerName = $computerName

      WinRMVersion = "N/A"

     }

    }

   }

   New-HashTable

  }

 }

 END {}

}