Unsolved
2 Posts
0
940
RecoverPoint API with PowerShell
Dear community,
Please bear with me if the answer to my problem is obvious. We've been using RP4VMs for about one year now but I am struggling getting information out of it via API.
We're running RP4VMs 5.3 SP2 P4. I would like to get the current health status, protected VMs etc. out via PowerShell.
The following works out but I think it's an outdated approach because we connect to vRPA cluster and not to Plugin Server:
### Works (For 5.2 with vRPA and vRPA credentials)
$RPCredUser = "admin"
$RPCredPWord = ConvertTo-SecureString -String "SomeSecretPW" -AsPlainText -Force
$RPCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $RPCredUser, $RPCredPWord
Invoke-RestMethod -Uri https://NameOfvRPACluster/fapi/rest/5_2/system/status -Credential $RPCred
The following, using Plugin Server with vSphere or Domain Credentials, does not work and I am wondering why.
### Does not work (For 5.3 with Plugin Server and VMware credentials)
$VMCred = Get-Credential
Invoke-RestMethod -Uri https://PluginServer.FQDN/api/v1/rp-clusters -Credential $VMCred
I asked a colleauge from our Linux team to test the below string which works out. So maybe I only have an issue in conjuction with PowerShell?
curl -X GET "https://PluginServer.FQDN/api/v1/vms?fields=name,status" -H "accept: application/json" -H "authorization: Basic Base64ConvertedCredentials==" --insecure
Can you provide a sample script for me to do an API request against Plugin Server using PowerShell? Your reply is much appreciated!
ChrisVH
2 Posts
0
May 31st, 2022 08:00
Found the issue. The following script does the trick:
$credential = Get-Credential # Enter like this: DOMAIN\Username
$password = $credential.GetNetworkCredential().password
$username = $credential.GetNetworkCredential().UserName
$domain = $credential.GetNetworkCredential().domain
$credPair = "$($domain)\$($username):$($password)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$headers = @{
Authorization = "Basic $encodedCredentials";
"Accept" = "application/json";
"Content-Type" = "application/json"
}
Invoke-RestMethod -Method Get -Uri 'https://PluginServer.FQDN/api/v1/vms?fields=name,status' -Headers $headers