• This topic has 3 replies, 3 voices, and was last updated October 29, 2020 by Michel G.

Trying to list protected VMs

  • Hi,

    I’m trying complete a major procedure in which I’d like to list the ZERTO protected VMs on my VMWARE environment

    I type the following command: Get-VmsReplicatingToHost -ZVMIP ZVMIP -ZVMPort 9080 -username myuser@domain -password mypwd -hostip HOSTIP but I get the following answer Error: Unknown Username or Incorrect Password , of course, I’m sure of my user and password

    What did I miss?

    Hi Michel,

    I haven’t used the PowerShell module but here is a REST API script I have cobbled together from the REST API documentation.
    Run it in the Powershell ISE from the Source ZVM and it will output you a list of Protected and Unprotected VMs for the site in CSV files.

     

    #———————————————————[Initialisations]——————————————————–
    # ZVM on Production side used to create VPGs
    $ZVMServer = “127.0.0.1:9669” #you can use local host if you run the script from the source ZVM.
    # Get Credentials to connect to ZVM API
    $Credentials = Get-Credential -Message “Please enter Username and Password for ZVM $($ZVMServer)”
    $username = $Credentials.UserName
    $password = $Credentials.GetNetworkCredential().Password

    #———————————————————–[Functions]————————————————————

    function getxZertoSession ($zvm, $userName, $password) {
    $xZertoSessionURL = $zvm+”session/add”
    $authInfo = (“{0}:{1}” -f $userName,$password)
    $authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
    $authInfo = [System.Convert]::ToBase64String($authInfo)
    $headers = @{Authorization=(“Basic {0}” -f $authInfo)}
    $body = ‘{“AuthenticationMethod”: “1”}’
    $contentType = “application/json”
    $xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURL -Headers $headers -Method POST -Body $body -ContentType $contentType -UseBasicParsing
    return @{“x-zerto-session”=$xZertoSessionResponse.headers.get_item(“x-zerto-session”)}
    }
    #———————————————————–[Ignore Cert]————————————————————
    #-Certificates That are not trusted need to be accepted
    add-type @”
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
    ServicePoint srvPoint, X509Certificate certificate,
    WebRequest request, int certificateProblem) {
    return true;
    }
    }
    “@
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

    #———————————————————–[Execution]————————————————————
    #https://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20RESTful%20APIs.pdf
    # Build Zerto REST API Url
    $ZertoRestURL = “https://$($ZVMServer)/v1/”
    # Get Zerto Session Header for Auth
    $ZertoSession = getxZertoSession “$($ZertoRestURL)” $username $password

    #API calls

    $VPGs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’vpgs’) -Headers $ZertoSession
    $ProtectedVMs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’vms’) -Headers $ZertoSession
    $UnprotectedVMs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’virtualizationsites/’+$SiteInfo.SiteIdentifier+’/vms’) -Headers $ZertoSession
    $SiteInfo = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’localsite’) -Headers $ZertoSession

    #Displaying Info

    $VPGs | select VPGName,VMsCount
    $ProtectedVMs | sort VPGName | Export-Csv -Path ‘C:\temp\ProtectedVMs.csv’
    $UnprotectedVMs | sort VPGName | Export-Csv -Path ‘C:\temp\UnProtectedVMs.csv’
    ii C:\temp

    You can use Zerto Analytics to export a list of protected and non protected VM’s to a csv file right from the web interface also.

    Thank you but Zerto Analytics needs a human action to export the file but my purpose was to be able to start a automatic collection of VM with a protected or not status through a Power Shell script for example

The forum ‘Scripting and APIs’ is closed to new topics and replies.