0

Please Help I have a website I have a problem stopping iis sometimes Please help with this code Condition does not work I want to do this

If you go to the next page success else Restart iis

$url = "https://alatheirvas.com:8443/Login.aspx" 
$username="hgeyf4125" 
$password="123456" 
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.Busy -eq $true) 
{ 
Start-Sleep 1; 
} 
$ie.Document.getElementById("Login2_UserName").value = $username 
$ie.Document.getElementByID("Login2_Password").value=$password 
$ie.Document.getElementById("Login2_LoginButton").Click();
while($ie.busy) {sleep 1}

The previous steps are correct

What is the next step to accomplish this

If logged in and go to the next page success

else Restart iis

if ($url = "https://alatheirvas.com:8443/agent/") {
"success"
} else {
iisreset 
}

---------------------------------------------------------------

I want to accomplish this in any way possible

---------------------------------------------------------------

3
  • You go to a http:// site and give login credentials? Are you sure that it should not be https://? May 2, 2018 at 0:32
  • Is there a better way? Probably. Calling Invoke-WebRequest with appropriate HTTP headers springs to mind. It depends on what you're trying to accomplish. May 2, 2018 at 1:41
  • thank you sir What I'm trying to do Is to login to the site If it is successful, Shi does not work If not successfully completed Works reboot iis Page Type - https I want to achieve this in any way possible May 2, 2018 at 8:46

1 Answer 1

0

Another way to solve this, is using Invoke-WebRequest. You can

$web=Invoke-WebRequest https://servicios.at.uy/ -SessionVariable sessionWeb
$Form = $web.Forms[0] #Notes below this code block
$Form.Fields["Login2_UserName"]="hgeyf4125"
$Form.Fields["Login2_Password"]="123456"
$status = Invoke-WebRequest -Uri ("https://servicios.at.uy/" + $Form.Action) -WebSession $sessionWeb -Method POST -Body $Form.Fields
if ($status.StatusDescription -ge "OK") {
    Write-host "Success"
} else {
    iisreset
}

The previous code block checks the status after the login process and, if that is "OK", then it is fine. Otherwise, restart IIS.

Notes: To validate the forms[0] corresponds to the correct form in your Website, you may to run the following:

$web = Invoke-WebRequest https://servicios.at.uy/
$Form = $web.Forms[0]
$Form.fields

In the column Key will be appear the name of the elements for login ("Login2_UserName" and "Login2_Password").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.