Trust SSL + ServicePointManager.ServerCertificateValidationCallback Property
Gets or sets the callback to validate a server certificate
An application can set the ServerCertificateValidationCallback property to a method to use for custom validation by the client of the server certificate. When doing custom validation, the sender parameter passed to the RemoteCertificateValidationCallback can be a host string name or an object derived from WebRequest (HttpWebRequest, for example) depending on the CertificatePolicy property.
When custom validation is not used, the certificate name is compared with host name used to create the request. For example, if Create(String) was passed a parameter of "https://www.contoso.com/default.hmtl", the default behavior is for the client to check the certificate against www.contoso.com.
Powershell Script:
$data = get-content InputLogs.csv
foreach($item in $data)
{
try
{
$Filename = [System.IO.Path]::GetFileName($item)
$tofile = "D:\DownloadFiles\" + $Filename
$webclient = New-Object System.Net.WebClient
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webclient.UseDefaultCredentials = $true
$webclient.DownloadFile($item, $tofile)
}
catch
{
write-output "$item" >> LogsExceptionCSV.csv
Write-Host Exception at $item and File not found
}
}
reference blogs:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/a260da46-b035-478c-9887-ba5a0a4777a0/powershell-10-trust-any-ssl-cert
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback(v=vs.110).aspx
Gets or sets the callback to validate a server certificate
An application can set the ServerCertificateValidationCallback property to a method to use for custom validation by the client of the server certificate. When doing custom validation, the sender parameter passed to the RemoteCertificateValidationCallback can be a host string name or an object derived from WebRequest (HttpWebRequest, for example) depending on the CertificatePolicy property.
When custom validation is not used, the certificate name is compared with host name used to create the request. For example, if Create(String) was passed a parameter of "https://www.contoso.com/default.hmtl", the default behavior is for the client to check the certificate against www.contoso.com.
Powershell Script:
$data = get-content InputLogs.csv
foreach($item in $data)
{
try
{
$Filename = [System.IO.Path]::GetFileName($item)
$tofile = "D:\DownloadFiles\" + $Filename
$webclient = New-Object System.Net.WebClient
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webclient.UseDefaultCredentials = $true
$webclient.DownloadFile($item, $tofile)
}
catch
{
write-output "$item" >> LogsExceptionCSV.csv
Write-Host Exception at $item and File not found
}
}
reference blogs:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/a260da46-b035-478c-9887-ba5a0a4777a0/powershell-10-trust-any-ssl-cert
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback(v=vs.110).aspx
No comments:
Post a Comment