Blog Viewer

PowerShell and the SecureSphere API

By Jim Burtoft posted 08-25-2021 07:36


Imperva has a lot of documentation around the SecureSphere API along with examples of how to use it.

We also have a lot of tools and utilities built around it with examples using cURL and python:

However, I was working with a customer that wanted to use PowerShell.  All we had to do was follow the cURL examples - authenticate, save the returned session id to a cookie, then make our API call.  While it seemed like a simple enough process, it wasn't working.  Whatever our problem was, the session id wasn't being parsed and saved and every subsequent API call said we weren't logged in.

It turns out that we were trying too hard.  Instead of parsing and saving everything, PowerShell allows us to just save the whole session and reuse it.  (see the PowerShell documentation at example 2 )

Below is an example of a working authentication and subsequent call.  Hopefully, you can use this (along with the other documentation/examples above) to help with your PowerShell integrations. 

You can use the code below as a test if you have DAM.  Just update the IP address and the Basic authentication string (username:password base64 encoded) and it should work for you.  (it just queries the vulnerability test list -- it doesn't change anything).  If you run it a second time in the same session, you will get an error that you are adding a header that already exists, but it should still work.

You should be able to use the same process to update SecureSphere WAF settings - it is the same API - you will just need a WAF-related call to test it.

Reach out to us here on the Imperva Community with any questions!

$headers.Add("Authorization", "Basic NOPETHISISHIDDEN=")
$LoginResponse = Invoke-WebRequest '' -SessionVariable 'Session' -Method 'POST' -Headers $headers
$ProfileResponse = Invoke-WebRequest '' -Method 'GET' -WebSession $Session
$ProfileResponse ‚Äč