2016-07-27 65 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