Skip to main content
Solved

Connecting commserve using powershell

  • September 21, 2022
  • 2 replies
  • 507 views

Forum|alt.badge.img+13

Hi Team,

Greetings! 

instead of Connect-CVServer command from PowerShell to connect commserve. is there a another way where we can connect commvault using PowerShell without providing credentials. 

i want to connect to commserver from PowerShell with token or something ? 

 

Best answer by LukeBrett

Hi @Allan0105,

You will always need to provide credentials to connect to the CommServe (or the Web Console). If you use CVPowershellSDK1, as you are doing now, you will provide credentials like this : Connect-CVServer -Server CommServeName -Credential domain\user.

If you use https://github.com/Commvault/CVPowershellSDKV2, you will need to run the following command: Invoke-SetupLogin -Username "#username" -Password "#base64Encodedpassword" -WebServerURL "http://#csName/webconsole/api"

If you prefer to retrieve a token to connect through the Web Console, here’s an example on how to do it:

# 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.

For more details, see the followin thread: 

https://community.commvault.com/developer-tools-50/powershell-invoke-restmethod-for-api-call-3912

Hope this helps you!

View original

LukeBrett
Byte
Forum|alt.badge.img+5

Hi @Allan0105,

You will always need to provide credentials to connect to the CommServe (or the Web Console). If you use CVPowershellSDK1, as you are doing now, you will provide credentials like this : Connect-CVServer -Server CommServeName -Credential domain\user.

If you use https://github.com/Commvault/CVPowershellSDKV2, you will need to run the following command: Invoke-SetupLogin -Username "#username" -Password "#base64Encodedpassword" -WebServerURL "http://#csName/webconsole/api"

If you prefer to retrieve a token to connect through the Web Console, here’s an example on how to do it:

# 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.

For more details, see the followin thread: 

https://community.commvault.com/developer-tools-50/powershell-invoke-restmethod-for-api-call-3912

Hope this helps you!


Forum|alt.badge.img+1
  • Byte
  • September 21, 2022

Reply


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