-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCV-RESTAPI-QOperationExecute.ps1
40 lines (32 loc) · 1.29 KB
/
CV-RESTAPI-QOperationExecute.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$WebServer = "http://whats-your-webserver-name:81/SearchSvc/CVWebService.svc"
$username = "setuserhere"
$password = "setpasshere"
$SCPClientArray = @()
$SubClientPolicyName = "Laptop plan Windows subclient policy"
$headers = @{}
$headers["Accept"] = "application/json"
$Body = @{
username = $username
password = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($password))
}
# Login to Commvault REST API
$Result = Invoke-RestMethod -Method POST -Uri "$WebServer/Login" -Headers $headers -ContentType "application/json" -Body $($Body | ConvertTo-Json)
# Save QSDK token
$headers["Authtoken"] = $Result.token
# Override accept header - qcommand only works with XML
# Set qoperation execscript command
# And do the work
$headers["Accept"] = "application/xml"
$Body = "qoperation execscript -sn GetSubclientPolicy.sql -si scp=$SubClientPolicyName"
$Result = Invoke-RestMethod -Method POST -Uri "$WebServer/QCommand" -Headers $headers -Body $Body
If ($Result.CVGui_GenericResp.errorCode) {
# Error handling
Write-Host "something went wrong, do something"
} else {
$ResponseXML.ExecScriptOutput.FieldValue.Clientname | ForEach-Object {
If($_ -notlike "*GetSubclientPolicycompleted*") {
$SCPClientArray += $_
}
}
Write-Host $SCPClientArray
}