Skip to content

Instantly share code, notes, and snippets.

@DWSR
Forked from riahc3/Invoke-Webrequest.ps1
Last active November 13, 2015 16:25
Show Gist options
  • Save DWSR/0a5094a1418e56239f27 to your computer and use it in GitHub Desktop.
Save DWSR/0a5094a1418e56239f27 to your computer and use it in GitHub Desktop.
Invoke-Webrequest
# establish initial connection to website
$initialRequest = Invoke-WebRequest -Uri 'http://192.168.100.97/csl/login' -SessionVariable WebSession1
#$initialrequest is now an object containing the html of the web request. get the form elements from the page
$form = $initialRequest.Forms[0] #outputting $form.fields to the screen will show you all the elements. Assuming 'username' and 'password'...
# update $form with username and password info and submit this back to the login webpage as POST
$form.fields.userpwd = "PASS"
$form.fields.username = "USER"
$loginRequest = Invoke-WebRequest -Uri ('http://192.168.100.97/csl/login' + $form.Action) -Method Post -Body $form.fields -WebSession $WebSession1
$tcpipRequest = Invoke-Webrequest -Uri 'http://192.168.100.97/form/Device?act=5' -Method Get -WebSession $WebSession1
$tcpsettingsform = $tcpipRequest.Forms[0]
$tcpsettingsform.gateway = '8.8.8.8'
$newrequest = Invoke-WebRequest -Uri "http://192.168.100.97$($form.action)" -Method $form.Method -Body $form.fields -WebSession $WebSession1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment