Skip to main content
Solved

use RESTAPI in a powershell script

  • January 27, 2022
  • 2 replies
  • 2500 views

Forum|alt.badge.img+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

Best answer by Mike Struening RETIRED

@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:

View original
Did this answer your question?
If you have a question or comment, please create a topic

2 replies

Mike Struening
Vaulter
Forum|alt.badge.img+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:


Onno van den Berg
Commvault Certified Expert
Forum|alt.badge.img+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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings