Skip to content

Instantly share code, notes, and snippets.

@Arefu
Created December 11, 2018 01:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arefu/263d2c3e8af822bb0ad17ea8e7203b15 to your computer and use it in GitHub Desktop.
Save Arefu/263d2c3e8af822bb0ad17ea8e7203b15 to your computer and use it in GitHub Desktop.
SpiceWorks API Access
[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
@phwitservices
Copy link

Thank you

@Arefu
Copy link
Author

Arefu commented Feb 3, 2019

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