I am new to powershell and I am trying to figure out how to insert my username and password into a website to login. Below is what I have come up with but failing to get it to work. Also the username and password are AD accounts if that matters.
URL of the site that will be launched.
$Url = “http://www.example.com”
$title = "User Authentication Required"
$message = "Enter user credentials for example.com"
$user = ""
$user_creds = $host.ui.PromptForCredential($title, $message, $user, "")
$IE = New-Object -com internetexplorer.application;
$IE.visible = $true;
$IE.navigate($url);
Wait a few seconds.
while ($IE.Busy -eq $true)
{Start-Sleep -Milliseconds 2000;}
The following UsernameElement, PasswordElement, and LoginElement need to be modified first.
# of the script for more details.
$IE.Document.getElementById(“userid”).value = $User_creds.Username
$IE.Document.getElementByID(“password”).value = $User_creds.password
$IE.Document.getElementById(“button-1034-btnIconEl”).Click()
This is the error I am getting now...
The property 'value' cannot be found on this object. Verify that the property exists and can be set. At C:\logon test.ps1:27 char:1 + $IE.Document.getElementById("userid").value = $User_creds.Username + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException The property 'value' cannot be found on this object. Verify that the property exists and can be set. At C:\logon test.ps1:28 char:1 + $IE.Document.getElementByID("password").value = $User_creds.password + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException
If I run this in v2 it still does not input the username but for the password it gives an error of System.Management.Automation. The enter code to login is working. Can someone please explain how can I get a username and password to input into the website page and the password needs to be hidden/secured.