GET produces the same kind of result, unfortunately. A colleague suggested turning on debug mode in my browser to get what the page is sending, then trying to recreate it. I'll give it a try later and see what I can see. Wget from Linux just knows what to do with it, but I'd like to get it with powershell if i can.
Sent from my Windows Phone ________________________________ From: Michael B. Smith<mailto:mich...@smithcons.com> Sent: 9/4/2014 5:28 PM To: powershell@lists.myitforum.com<mailto:powershell@lists.myitforum.com> Subject: [powershell] RE: invoke-webrequest to click a download link on a redhat satellite web page It probably needs to be a GET instead of a POST. But I don’t have any easy way to test. From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On Behalf Of Mote, Todd Sent: Thursday, September 4, 2014 6:09 PM To: 'powershell@lists.myitforum.com' Subject: [powershell] invoke-webrequest to click a download link on a redhat satellite web page I have an odd request. I’m trying to invoke a “download csv” link on a redhat satellite web page, specifically the “download csv” on the systems overview to get the csv that reports on errata so I can do some other stuff with it in SSRS and SCCM. I’ve managed to get logged on and navigate my way to the page and even find the link, but I can’t seem to get the invoke-webrequest to “click the link” and have what’s returned be the csv, like what happens when I click on the same link in a browser. $r = Invoke-WebRequest "https://satellite.server.edu/rhn/Login.do" -SessionVariable sat $form=$r.Forms[0] $form.fields["username"] = "username" $form.fields["password"] = "password" $login=Invoke-WebRequest -Uri ("https://satellite.server.edu" + $form.Action) -WebSession $sat -Method POST -Body $form.Fields $o=Invoke-WebRequest -Uri ("https://satellite.server.edu" + $login.links[9].href) -WebSession $sat -Method POST -Body $form.Fields Invoke-WebRequest -Uri("https://satellite.server.edu" + $o.links[177].href) -WebSession $sat -Method POST -Body $form.Fields The last uri ends up getting extended to “https://satellite.server.edu/rhn/CSVDownloadAction.do?__CSV__exportColumnsParam=exportColumns_1680466951&__CSV_queryMode=query_1680466951&__CSV_uniqueName=1680466951” which is the same link that I get from the browser when I copy the shortcut for the “Download CSV” link. But when the last invoke is called a file is not returned. Just the same type of output the other invoke-webrequests return. How can I “click the link” and get a file back instead of StatusCode : 200 StatusDescription : OK Content : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="e... RawContent : HTTP/1.1 200 OK Content-Length: 7675 Content-Type: text/html;charset=UTF-8 Date: Thu, 04 Sep 2014 21:40:03 GMT Set-Cookie: pxt-session-cookie=395908x7e6d5b176f78d08c740949b8cf4a4a21; Expires=Fri, ... Forms : {form1} Headers : {[Content-Length, 7675], [Content-Type, text/html;charset=UTF-8], [Date, Thu, 04 Sep 2014 21:40:03 GMT], [Set-Cookie, pxt-session-cookie=395908x7e6d5b176f78d08c740949b8cf4a4a21; Expires=Fri, 05-Sep-2014 07:40:03 GMT; Path=/; Secure; HttpOnly]} Images : {@{innerHTML=; innerText=; outerHTML=<IMG id=rhLogo alt="Red Hat" src="/img/logo_vendor.png">; outerText=; tagName=IMG; id=rhLogo; alt=Red Hat; src=/img/logo_vendor.png}, @{innerHTML=; innerText=; outerHTML=<IMG id=rhnLogo accessKey=2 alt="RHN Satellite" src="/img/logo_product.png">; outerText=; tagName=IMG; id=rhnLogo; accessKey=2; alt=RHN Satellite; src=/img/logo_product.png}, @{innerHTML=; innerText=; outerHTML=<IMG src="/img/rhn-icon-warning.gif">; outerText=; tagName=IMG; src=/img/rhn-icon-warning.gif}} InputFields : {@{innerHTML=; innerText=; outerHTML=<INPUT accessKey=4 maxLength=40 name=search_string autofocus>; outerText=; tagName=INPUT; accessKey=4; maxLength=40; name=search_string; autofocus=}, @{innerHTML=; innerText=; outerHTML=<INPUT type=hidden value=true name=submitted>; outerText=; tagName=INPUT; type=hidden; value=true; name=submitted}, @{innerHTML=; innerText=; outerHTML=<INPUT class=button type=submit align=top value=Search name=image-1>; outerText=; tagName=INPUT; class=button; type=submit; align=top; value=Search; name=image-1}} Links : {@{innerHTML=change; innerText=change; outerHTML=<A href="/rhn/account/LocalePreferences.do">change</A>; outerText=change; tagName=A; href=/rhn/account/LocalePreferences.do}, @{innerHTML=Knowledgebase; innerText=Knowledgebase; outerHTML=<A href="http://kbase.redhat.com/">Knowledgebase</A>; outerText=Knowledgebase; tagName=A; href=http://kbase.redhat.com/}, @{innerHTML=Documentation; innerText=Documentation; outerHTML=<A href="/help">Documentation</A>; outerText=Documentation; tagName=A; href=/help}, @{innerHTML=username; innerText=username; outerHTML=<A href="/rhn/account/UserDetails.do">username</A>; outerText=username; tagName=A; href=/rhn/account/UserDetails.do}...} ParsedHtml : mshtml.HTMLDocumentClass RawContentLength : 7675 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1