Solved

Commvault Powershell SDK v2

  • 23 September 2022
  • 2 replies
  • 248 views

Badge +1

Hello all, is anyone using the Powershell SDK v2?  I see it hasn’t been touched since initial commit, is this still a thing?  I really like the v1 and wanted to see what else is now available in v2.  https://github.com/Commvault/CVPowershellSDKV2

 

The documentation is scarce at best and CV docs still references SDK v1 which is not the same as v2.  From the github page it just says to use Invoke-SetupLogin, which I am able to connect and get a token.  But then how do I use the cmdlets at that point?  When I run a command afterwards I just get “Unauthorized”  In v1 once you run connect-CVServer, you can run any commands against the currently logged in Commcell.

 

I really think this PS module is a great thing and hope it is still being developed.  The API is nice but the PS code is much easier to use and less code involved.

 

Thanks for any details!

icon

Best answer by LukeBrett 23 September 2022, 16:08

View original

2 replies

Userlevel 1
Badge +5

HI @ptmorris

I never had an “Unauthorized” message while using PowershellSDKV2. Make sure you are running Feature Release 26 or later. Here’s a sample of the output you get from SDKV2 :

# Output sample

PS C:\Users\Administrator\Documents\WindowsPowerShell> Get-MediaAgent

Description DisplayName Id Name OfflineReason Status Version
----------- ----------- -- ---- ------------- ------ -------
commserve 2 commserve ONLINE 11 SP28.19


PS C:\Users\Administrator\Documents\WindowsPowerShell> Get-ServerGroup

Association Id IsCompanySmartClientGroup IsSyncInProgress Name
----------- -- ------------------------- ---------------- ----
AUTOMATIC 1 False Infrastructure
AUTOMATIC 2 False Proxy Clients
AUTOMATIC 3 False Media Agents
AUTOMATIC 4 False Laptop Clients

Overall, I prefer SDK1 because the output handling is much better, but it has a very limited number of cmdlets. SDK2 is more of a work in progress. It is not really sysadmin friendly. If you have some development skills in PowerShell, you can easily customize the functions. 

If you wish to do your own API calls, here’s how you can get a token on your own in PowerShell :

# How to connect and get a token

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Content-Type", "application/json")

$body = "{`n `"password`": `"Password_in_Base64`",`n `"username`": `"admin`",`n `"timeout`" : 30`n}"

$response = Invoke-RestMethod 'http://WebServerName/webconsole/api/Login' -Method 'POST' -Headers $headers -Body $body
$token = $response.token

Once you have the token, you can issue commands from https://api.commvault.com/#3707251b-cc26-8c00-fb24-d007e6d8d236. Make sure you select Language: PowerShell-REST Method.

Hope this helps you in your Commvault PowerShell journey!

Badge +1

I was able to Get-MediaAgent to work.  Today a different error from get-virtualmachine, so from what you said seems like these aren’t ready for mainstream use yet.  I hope they continue to work on this but doesn’t look like anything new in over 8 months.  Guess I am stuck with v1 for now. 

Yes I am able to use API as I said, I just prefer the easier Powershell Cmdlets

 

Thanks for your reply

 

 

Reply