Author Posts

February 9, 2017 at 6:37 pm

Basically there is a requirement, where i need to login to a web portal by passing on credentials through windows security pop up (like what we have to login for tomcat admin service console) & then click on a reload button on the next screen.

The script for clicking on the Reload button works fine but the problem is i have to manually login through the windows pop up & keep one active session open all the time & this is not possible when i want to add this script to a task scheduler.

The moment it tries to open http://localhost:9001/test/Admin/RuntimeParameters.jsp this is where it pops up with the windows security box & there is no way known to me to pass on the creds to this section. I need help for this piece.

	$ie = New-Object -com InternetExplorer.Application 
	start-sleep 4
	while($ie.ReadyState -ne 4) {start-sleep -m 100} 
	if ($? -eq "True")
		Write-host "Reload of the Admin page completed successfully" -ForegroundColor green
		Write-output "Reload of the Admin page completed successfully"
		Write-host "Reload of the Admin page Failed" -ForegroundColor red
		Write-output "Error: Reload of the Admin page Failed"

So i need help to know as how can we pass on credentials through PS script to login through a windows security pop up window not sure how PS can interact with this pop up window.

Thanks for checking & providing expert advise.

February 11, 2017 at 5:28 pm

You can try to pass username and password in the URL.



Just make sure the username and password don't include the following single characters

: @ /

February 11, 2017 at 5:31 pm

The other alternative would be to use the Invoke-WebRequest cmdlet if you don't need to display the page on a screen.

$creds = Get-Credential
$response = Invoke-WebRequest -UseBasicParsing -Uri http://localhost:9001/test/Admin/RuntimeParameters.jsp -Credential $creds
# do something with the response

February 14, 2017 at 8:26 pm

Thanks Daniel for the response but it seems, current version of IE doesn't support this method of passing on the creds through URL anymore 🙁

February 14, 2017 at 9:05 pm

Hi Daniel, instead of Invoke-WebRequest i tried this which allows to login & allows to fetch the web page code details instead of popping up the web page itself.

$url = "http://localhost:9001/test/Admin/RuntimeParameters.jsp"
$user = "username"
$pass = "pass"
$secPass = convertTo-secureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user,$secPass)

$data = Invoke-RestMethod $url -Credential $cred

However, is there way to open the web page after it logs in like i had $url.visible=$true using $ie = New-Object -com InternetExplorer.Application & the navigating to this URL. I guess we cannot merge two invoke requests in the same method.

Please advise.

February 15, 2017 at 8:34 pm

I can use both the invoke methods & assume am able to login fine but that's all happening in the background.

The requirement is to click on a particular button on this web page after i am logged in into this webpage.

Tried both & get runtime error

$url = "http://localhost:9001/test/Admin/RuntimeParameters.jsp"
$user = "username"
$pass = "pass"
$secPass = convertTo-secureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user,$secPass)

$response = Invoke-WebRequest -UseBasicParsing -Uri $url -Credential $cred

Write-host $response.StatusCode

Also tried –

$Link=$response.Document.getElementsByTagName("input") | where-object {$_.type -eq "submit"}

I am trying to click The actual button from the html code from the web page is

form action = "#" method="POST"
input type="submit" value="Reload" name="Reload"

February 16, 2017 at 10:39 am

Thanks for the update. I think you'll need to look at Selenium which is web browser automation framework ( and it is free as far as I know.

February 17, 2017 at 10:32 am

Have you tried

Get-Credential | Export-Clixml -Path 

This will bring up the UN/PW windows dialogue box. When you enter your credentials, this will write the UN and PW to an encrypted text file (as stipulated by your given path). For instance

Get-Credential | Export-Clixml -Path C:\Cred\EncryptedCredentials.txt

You can then add the content of this file to a variable in your script.

$MyCredential = Import-Clixml -Path C:\Cred\EncryptedCredentials.txt

Which can later be refeferenced by a -credentials parameter in your script.

This works fine for me when running scripts that need to authenticate against an externeal FTP server.

Caveat: The acount you are logged in within when you create the encrypted credentials will need to be the same account you want to run the scripts under.

February 17, 2017 at 11:52 am

*need to run the scripts under.