我是PowerShell的新手。当我尝试执行以下代码时,出现错误:
“在语句块或类型定义中缺少结束 '}'。”
下面是代码,我不确定我在哪里失踪。
$path = "C:\Users\Dr.Salya\Downloads"
$filename = "rateonlyl-455.zip"
$url = "https://vertexinc.custhelp.com/app/utils/login_form"
$url2 = "https://download-ie.flexnetoperations.com/512175/1386/77/17129077/rateonlyl-455.zip?ftpRequestID=2321180473&server=download-ie.flexnetoperations.com&dtm=DTM20200820125043ODA0MDU5NDEz&authparam=1597953043_bf5ca04b9a74eeb53a272c20ea148517&ext=.zip/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.silent = $false
$ie.navigate("$url")
while($ie.ReadyState -ne 4){start-sleep -m 100}
if ($ie.document.url -Match "invalidcert"){
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"}
$sslbypass.click()
start-sleep -s 5
}
$ie.Document.IHTMLDocument3_getElementById("username").click()
$ie.Document.IHTMLDocument3_getElementById("username").value ='********'
$ie.Document.IHTMLDocument3_getElementById("password").click()
$ie.Document.IHTMLDocument3_getElementById("password").value ='1234'
$ie.Document.IHTMLDocument3_getElementById("").click()
start-sleep 5
$ie.navigate($url2)
start-sleep 10
$ie.Document.body.outerHTML | Out-File -FilePath $path/$filename
错误:
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:22 char:1
+ $ie.Document.IHTMLDocument3_getElementById("username").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:23 char:1
+ $ie.Document.IHTMLDocument3_getElementById("username").value ='nnaisv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:24 char:1
+ $ie.Document.IHTMLDocument3_getElementById("password").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:25 char:1
+ $ie.Document.IHTMLDocument3_getElementById("password").value ='Vertex ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:26 char:1
+ $ie.Document.IHTMLDocument3_getElementById("").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull