Use PowerShell v3 to Keep a CookieJar and POST to a Web Form That Prohibits XSS
In my previous post, I outlined how to use PowerShell v2 to keep a CookieJar and POST to a Web Form that Prohibits XSS. The code was 35 lines long. Upon seeing my post, Lee Holmes suggested using PowerShell v3's Invoke-WebRequest instead to get my code down to 1/5th of its original size.
I'm astounded at how easy Invoke-WebRequest made this task. It took care of knowing what type of authentication is required (Basic, in my example), and the cookie jar/session. So now I'm down from 35 lines of code to this:
$url = "https://vcenter.base.local/mob/?moid=vpxd-securitymanager&method=reloadSslCertificate&vmodl=1" [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} #ignore ssl warning $creds = Get-Credential -Credential "$env:userdomain\$env:username" $wr = Invoke-WebRequest $url -SessionVariable vmware -Credential $creds $wr = Invoke-WebRequest -Uri $url -WebSession $vmware -Method POST -Body $wr
Bravo, PowerShell team :D