Login into a website

Jose Espinal 1 Reputation point

Hi gurus

I am very new to this Powershell script so go easy on me, I have the following trying to connect to website using PowerShell:

$LogicM= Invoke-webrequest -uri "https://website/" -sessionVariable sbv
$LMform= $LogicM.forms[0]
$r=invoke-webrequest -uri (https://website/+$LMform.action) -webSession $sbv -Method Get -Body $LMform.fields

but I get the following error :

invoke-webrequest :
404 Not Found
back home
At line:1 char:4

I have the following as a form
Id Method Action Fields
-- ------ ------ ------
login-section get javascript:; {[username, ], [password, ], [rem, on]}

what am I doing wrong , thanks for any help

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,404 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jose Espinal 1 Reputation point


    when I run the $logicM.forms from the code above, I get this:
    Id Method Action Fields
    -- ------ ------ ------
    login-section get javascript:; {[username, ], [password, ], [rem, on]}

    which I think it tells me the form uses Get and not post, but again I am to new to be sure of this , what are the steps I need to follow to get the info needed to make this script work


    0 comments No comments

  2. Limitless Technology 43,996 Reputation points

    Hello there,

    404 means the URL is wrong can you try this different URL and check the output?

    Since Powershell version 7.0 Invoke-WebRequest has -SkipHttpErrorCheck switch parameter.


    This parameter causes the cmdlet to ignore HTTP error statuses and continue to process responses. The error responses are written to the pipeline just as if they were successful.

    WebRequestPSCmdlet.SkipHttpErrorCheck Property



    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments