Solved

use RESTAPI in a powershell script

  • 27 January 2022
  • 2 replies
  • 1824 views

Userlevel 2
Badge +7

Hi All,

i need help to create a powershell script using REST API command.

i don’t found a lot of documentation for the specific use of REST API in powershell.

in the community in have found a sample for POST LOGIN 

$headers = @{}
$headers.add("Accept", "application/json")
$headers.add("Content-Type","application/json")

$username = "user"
$password = "passwordtoencode"
$encodePassword = [convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($password))

$body = @{username=$username;password=$encodePassword;}

$response = Invoke-RestMethod 'http://hostname/webconsole/api/Login' -Method POST -Headers $headers -Body $($body | ConvertTo-Json )

$response

But somenone have sample for all kind of REST API sample ?

Thank in advance

Christophe

icon

Best answer by Mike Struening RETIRED 27 January 2022, 18:24

View original

If you have a question or comment, please create a topic

2 replies

Userlevel 7
Badge +23

@christophe , have you checked out the examples on https://api.commvault.com/ ?

That page has pretty much everything (and if it doesn’t, let me know and I’ll get it addressed) :nerd:

Userlevel 7
Badge +19

@christophe I would recommend looking into the PowershellSDK which simplifies the consumption of the APIs while using Powershell. And if you are running FR26 already then I have good news because development release a brand new version today! 

V1 version: https://github.com/Commvault/CVPowershellSDK
V2 version (requires FR26): https://github.com/Commvault/CVPowershellSDKV2

V1 documentation → https://documentation.commvault.com/11.24/essential/101893_commvault_powershell_module.html