Login into a website

Jose Espinal 1 Reputation point
2022-10-14T03:12:56.547+00:00

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]
$LMform.fields["username"]="user"
$LMform.fields["password"]="ymca"
$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,551 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jose Espinal 1 Reputation point
    2022-10-16T01:17:13.587+00:00

    D.

    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

    Thanks

    0 comments No comments

  2. Limitless Technology 44,391 Reputation points
    2022-10-18T07:22:10.423+00:00

    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.

    -SkipHttpErrorCheck

    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

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.webrequestpscmdlet.skiphttperrorcheck?view=powershellsdk-7.0.0

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

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.