.net 无法在我的PS1文件中绕过CertificateValidation

.net 无法在我的PS1文件中绕过CertificateValidation,.net,powershell,ssl,taskscheduler,.net,Powershell,Ssl,Taskscheduler,我想编写一个PS1文件,使用windows任务调度器及时调用该文件(主要是每天调用2次),现在PS1文件的目的是调用我们的内部网站以保持应用程序池处于活动状态,因为我正在应用程序池范围内运行一些后台作业 因此,我编写了以下文件: $request = [System.Net.WebRequest]::Create("https://localhost/") $response = $request.GetResponse() $response.Close() 但这将引发以下错误: At **

我想编写一个PS1文件,使用windows任务调度器及时调用该文件(主要是每天调用2次),现在PS1文件的目的是调用我们的内部网站以保持应用程序池处于活动状态,因为我正在应用程序池范围内运行一些后台作业

因此,我编写了以下文件:

$request = [System.Net.WebRequest]::Create("https://localhost/")
$response = $request.GetResponse()
$response.Close()
但这将引发以下错误:

At ******\AppPoolActivation.ps1:4 char:67 + ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, ... + ~ Missing argument in parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingArgument 使用“0”参数调用“GetResponse”时出现异常:“基础连接已关闭:无法为SSL/TLS安全通道建立信任关系。”

因此,我修改了我的ps1文件,以绕过安全证书,如下所示:

$request = [System.Net.WebRequest]::Create("https://localhost/")
$response = $request.GetResponse()
$response.Close()
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => certificate.Issuer == "CN=localhost";
但这将引发以下错误:

At ******\AppPoolActivation.ps1:4 char:67 + ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, ... + ~ Missing argument in parameter list. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingArgument 在******\AppPoolActivation.ps1:4 char:67处 +ServicePointManager.ServerCertificateValidationCallback+=(发件人、证书。。。 + ~ 参数列表中缺少参数。 +CategoryInfo:ParserError:(:)[],ParentContainerErrorRecordException +FullyQualifiedErrorId:缺少辩论
那么,有人能建议我如何在执行后台作业之前调用本地主机以保持我的应用程序池处于活动状态,并绕过安全证书吗?

[System.Net.ServicePointManager]::ServerCertificateValidationCallback={$true}
?@beatcracker好的,谢谢,但是我怎么能说只绕过本地主机呢?显然,使用
if..else
语句。