How Do I start


I am starting a project in which I need to automate a report building process.

I am presented with a webpage, where in I need to automate the entering of the username and password, then hit Login.
There are hyperlinks on the page wherein one of the Link says Explore Data. When clicked on this there is another section below it from where I need to select data from a filtered list.After the selection is made I need to click on a Button called Add Clause.

Then need to click on Generate This will generate a excel report which needs to be exported to the desktop.


I have started with the first step.

$url = “https://x.x.x.x

$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;

while ($ie.Busy -eq $true)
Start-Sleep -Milliseconds 1000;
$ie.Document.getElementById(“login”).value = $username

<selecting a link>

while($ie.busy) {sleep 1}
$link = $ie.Document.getElementsByTagName(‘A’) | where-object {$_.innerText -eq ‘Click here’}

This snippet just opens the page but doesn’t input the username and password.

Can someone please help me out?

Any help will be appreciated.


Kaustubh Kumar

So, this is really not a PowerShell thing per se, and PowerShell isn’t always the easiest way to do this. You’re using a VERY old COM object from Internet Explorer, which is the only way PowerShell CAN do this, but it’s not a modern programming API and it won’t work in all situations. It can sometimes be easiest to submit data to the form directly using Invoke-WebRequest (which has examples in its help).

If you Google “web scraping in powershell” you’ll see a number of articles on this subject. They do get pretty detailed, but keep in mind that everything you’re using is technically older than PowerShell, and going through several programming layers to make it work in PowerShell. So it can be pretty hit-or-miss. And you’ll need to know a decent amount about Javascript programming, because that’s basically how you interact with the Document Object Model. For example, the “text” property, versus the “value” property, might be useful in this exact situation.

Finally, keep in mind that a better post title than “How do I start” can help the right people find your post here on the site. Anything more specific (“Need help filling in a web form,” perhaps) can draw the right people to your question.

Also have the browser’s web developer tools in mind. They can show you the http queries.