# How to code it using Powershell Script?

**URL:** <https://forums.powershell.org/t/how-to-code-it-using-powershell-script/10000>\
**Category:** PowerShell Help\
**Created:** [January 20, 2018, 7:23am UTC](https://forums.powershell.org/t/how-to-code-it-using-powershell-script/10000 "2018-01-20T07:23:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oempower](https://avatars.discourse-cdn.com/v4/letter/o/e79b87/32.png) [@oempower](https://forums.powershell.org/u/oempower)\
**Post date:** [January 20, 2018, 7:23am UTC](https://forums.powershell.org/t/how-to-code-it-using-powershell-script/10000/1 "2018-01-20T07:23:54Z")

</div>

I would like to know on how to login using PowerShell, and what wrong is following coding?

Does anyone have any suggestions?  
Thanks in advance for any suggestions

**HTML Coding**

# 

# 

# 

#E-Mail \*

# 

#Password \*

# 

# 

**PowerShell Script**  
$clnt = new-object System.Net.WebClient  
$URL = “[https://www.sample.com/login/](https://www.sample.com/login/)”  
$token = “aaabbbcccjfheh48u8jdjd”  
$username = “sample\_username”  
$password = “sample\_password”  
$postParams = @{FORM\_TOKEN=$token; LoginForm\_email=$username; LoginForm\_password=$password}  
Invoke-WebRequest -URi $URL -Method POST -body $postParams

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [January 21, 2018, 3:01pm UTC](https://forums.powershell.org/t/how-to-code-it-using-powershell-script/10000/2 "2018-01-21T15:01:38Z")

</div>

What you are doing and asking about is s very common thing. You just have to make sure you are calling the objects of the fomr correctly.

There are lots of examples of how to do this all over the web.

For example:  
‘[Powershell : Automated Login to All your Websites in One Go. – Geekeefy](http://geekeefy.wordpress.com/2015/06/07/powershell-automated-login-to-all-your-websites-in-one-go)’

There are direct examples in the PoSH built-in help files …

```
# Get parameters, examples, full and Online help for a cmdlet or function
    (Get-Command -Name Invoke-WebRequest).Parameters
    Get-help -Name Invoke-WebRequest -Examples
    Get-help -Name Invoke-WebRequest -Full
    Get-help -Name Invoke-WebRequest -Online
```

… and sample scripts provide via the MS [PowerShellGallery.com](http://PowerShellGallery.com) and the Scripting Guys blog.

Automate login to website  
A script to log in to a website, parse the contents into objects, click some buttons and tick some checkboxes.  
‘[gallery.technet.microsoft.com/scriptcenter/9d66f3bd-a051-4b0f-833c-868de0f0b653](http://gallery.technet.microsoft.com/scriptcenter/9d66f3bd-a051-4b0f-833c-868de0f0b653)’

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/how-to-code-it-using-powershell-script/10000/3 "2024-05-16T20:36:49Z")

</div>


