Powershell SSL证书警告中断IE自动化

Powershell SSL证书警告中断IE自动化,powershell,internet-explorer,ssl,Powershell,Internet Explorer,Ssl,我需要在CUCM(Cisco Unified Communications Manager)上自动执行一些操作,因此我正在使用PowerShell的InternetExplorer.Application 但是,我发现了一个与SSL错误相关的问题: 接下来,我首先找到转到网页链接并发送一个点击操作-这非常有效 但是,当下一个页面加载时(我需要输入登录详细信息),我的脚本无法使用 在此对象上找不到属性“value”。验证该属性是否存在,并且是否可以 准备好了。 在C:\temp\termTEST

我需要在CUCM(Cisco Unified Communications Manager)上自动执行一些操作,因此我正在使用PowerShell的
InternetExplorer.Application

但是,我发现了一个与SSL错误相关的问题:

接下来,我首先找到转到网页链接并发送一个点击操作-这非常有效

但是,当下一个页面加载时(我需要输入登录详细信息),我的脚本无法使用

在此对象上找不到属性“value”。验证该属性是否存在,并且是否可以 准备好了。 在C:\temp\termTEST\TermForm.ps1:34字符:2 +$document.getelementsbyname(“j_用户名”)[0]。值='sebastian.k。。。 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidOperation:(:)[],运行时异常 +FullyQualifiedErrorId:PropertyAsignmentException

但是我可以确认登录字段存在,因此
$ie
$document
对象似乎被回收或类似的东西,这意味着我无法访问这些字段

我怎样才能克服这个问题

剧本:

$ie = New-Object -ComObject internetexplorer.application
$ie.navigate("https://10.40.193.31/ccmadmin/phoneFindList.do")
$ie.visible = $true
while ($ie.busy) { sleep 1 }
$global:document = $ie.document
#A while loop to check for IE certificate errors on the page and continue loading the page anyway if there are any
while ($document.readyState -ne 'complete') { sleep -Milliseconds 100 }
if ($document.getelementbyID("overridelink"))
{
    $document.getelementbyid("overridelink").click();
    while ($ie.busy) { sleep 1 }
    $document;
    while ($document.readyState -ne 'complete') { sleep -Milliseconds 100 }
}
#Loading the credentials from the queryCredentials function to log onto the portal
$document.getelementsbyname("j_username")[0].value = 'Bassie' # ERROR OCCURS HERE
$document.getelementsbyname("j_password")[0].value = 'password'
$document.getelementbyid("logonform").submit()
如果我手动单步执行代码并实际单击continue链接(导致
If
语句跳过),则登录字段填充得很好,因此这肯定与证书错误消息有关

我尝试将证书安装到我的机器上,但由于某种原因,我仍然收到了消息。还联系了我们的支持团队以更新证书,但他们拒绝帮助我,因此我只能依靠自己。

以下是一些事实:

  • IE自动化将无法工作,除非该网站不受信任(在受信任的站点区域),并且有一个由受信任的权威机构签署的证书
  • 证书应提供给fqdn或主机名,而不是ip地址
  • 运行IE/Powershell的客户端需要在用户证书>受信任的根证书颁发机构中安装根CA参与签名链
  • 如果您请求并购买ssl证书,这将更容易(它们并不昂贵)

    以下是您可以执行的操作:

  • 请为这个网站提供一个主机名,即cucm.company.org
  • 创建证书请求csr文件和私钥,如下所示

    openssl req-nodes-new-newkey rsa:4096-subc'/C=AU/O=Company Limited/CN=cucm.Company.org/OU=Phones/L=Sydney/ST=new South Wales/'-keyout cucm.Company.org.key-out cucm.Company.org.csr

  • 提出请求,得到批准

  • 按照与此类似的说明在CUCM网站上安装web服务器sll证书:

  • 添加到IE中的受信任站点区域