2016-07-27 19 views
0

我试图通过登录到电子邮件来激活帐户的过程自动化,当我不在以下代码的业务网络上时,它有效。Powershell私人启动IE并登录到页面

$username = "user" 
$password = "pass" 
$url = "url" 

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true 
$ie.navigate($url) 

while ($ie.Busy -eq $true){Start-Sleep -seconds 1;} 

$usernamefield = $ie.Document.getElementByID('UsernameTextBox') 
$usernamefield.value = $username 

$passwordfield = $ie.Document.getElementByID('PasswordTextBox') 
$passwordfield.value = $password 

$ie.document.getElementById("ctl00_ContentPlaceHolder1_SubmitButton").click()` 

我的问题是,一旦连接到商业网络则使用SSO登录,所以我不明白摆在用户名和密码的选项。为了能够输入用户名和密码,我需要以私人模式启动IE。我已经能够用启动进程命令私人启动IE,但是我找不到一种方法来选择窗口来输入用户名和密码。

有没有一种方法可以使用powershell登录到私人浏览器的网站?

回答

1

您可以通过启动启动进程来获得专用IE的句柄,如您所述。

Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -ArgumentList ' -private http://bogus.bogus' 

然后你就可以发现它连接到它 -

$Shell = New-Object -Com Shell.Application 
$apps = $shell.windows() 
$ie = $apps | where { $_.locationname -eq 'http://bogus.bogus/' } 

快乐的脚本。 :)

+0

更好'启动过程iexplore.exe -ArgumentList' - 私人http:// bogus.bogus'' – DisplayName

相关问题