[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true)] | |
[string] | |
$ComputerName, | |
[int] | |
$Port = 443 | |
) | |
$Certificate = $null | |
$TcpClient = New-Object -TypeName System.Net.Sockets.TcpClient | |
try { | |
$TcpClient.Connect($ComputerName, $Port) | |
$TcpStream = $TcpClient.GetStream() | |
$Callback = { param($sender, $cert, $chain, $errors) return $true } | |
$SslStream = New-Object -TypeName System.Net.Security.SslStream -ArgumentList @($TcpStream, $true, $Callback) | |
try { | |
$SslStream.AuthenticateAsClient('') | |
$Certificate = $SslStream.RemoteCertificate | |
} finally { | |
$SslStream.Dispose() | |
} | |
} finally { | |
$TcpClient.Dispose() | |
} | |
if ($Certificate) { | |
if ($Certificate -isnot [System.Security.Cryptography.X509Certificates.X509Certificate2]) { | |
$Certificate = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList $Certificate | |
} | |
Write-Output $Certificate | |
} |
This comment has been minimized.
This comment has been minimized.
This works perfectly but we have to enter server names manually..how to find out SSL certificate installed servers in a domain ? |
This comment has been minimized.
This comment has been minimized.
great, thank you! |
This comment has been minimized.
This comment has been minimized.
Thanks! Do this work for SNI? |
This comment has been minimized.
This comment has been minimized.
@euyuil if line 23 |
This comment has been minimized.
This comment has been minimized.
Is there a timeout value or validation of certificate? |
This comment has been minimized.
This comment has been minimized.
@sahmedz11 As it is currently written, the script will use default .NET timeouts. You can augment the script to set To implement a custom TCP connection handshake timeout, significant changes would be required to replace The script also very explicitly does not perform any certificate validation, its purpose is to return the certificate for deeper inspection, valid or not. However you can modify the |
This comment has been minimized.
thanks