Created
December 11, 2018 01:50
-
-
Save Arefu/263d2c3e8af822bb0ad17ea8e7203b15 to your computer and use it in GitHub Desktop.
SpiceWorks API Access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
[string] $url = "http://{SERVER}/pro_users/login", | |
[string] $username = "{Email}", | |
[string] $password = '{Password}' | |
) | |
$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0" | |
$headers = @{"Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-US,en;q=0.5";} | |
$r = Invoke-WebRequest ($url) -SessionVariable session -UserAgent $userAgent -Headers $headers | |
$CookieContainer = New-Object System.Net.CookieContainer | |
$session.Headers.Add("Cookie", $CookieContainer.GetCookieHeader($url)) | |
$formFieldsText = "authenticity_token="+[System.Net.WebUtility]::UrlEncode($r.Forms[0].Fields["authenticity_token"])+"&_pickaxe=%E2%B8%95&pro_user%5Bemail%5D="+[System.Net.WebUtility]::UrlEncode($username)+"&pro_user%5Bpassword%5D="+[System.Net.WebUtility]::UrlEncode($password)+"&pro_user%5Bremember_me%5D=0" | |
$Reply = Invoke-WebRequest ($url) -WebSession $session -Method POST -Body $formFieldsText -UserAgent $userAgent -Headers $headers -ErrorAction SilentlyContinue | Out-Null | |
Invoke-RestMethod -WebSession $session -Uri "http://{SERVER}/api/remote_collectors.json" -UserAgent $userAgent -Headers $headers -Method GET |
If you're looking for other PowerShell stuff, check out my https://github.com/Arefu/WorkHarderNotSmarter repo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you