• This topic has 2 replies, 2 voices, and was last updated May 6, 2020 by Sohail V.

Check if a vm is in a vpg or not

  • Hello

    I am looking for a script that can be run against a list of server (a text file) and checks for every vm if it is protected under Zerto or not. Any help would be greatly appreciated

    Thanks

    Hi Sohail,

    I hope this helps you. This is a PowerShell script. Copy and run it on the Windows ISE on the ZVM at the Production side.

     

    #———————————————————[Initialisations]——————————————————–
    # ZVM on Production side used to create VPGs
    $ZVMServer = “localhost:9669″

    $cred = Get-Credential
    $username = $cred.UserName
    $password = $cred.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
    $SiteInfo = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’localsite’) -Headers $ZertoSession #gather sites attached to the ZVM
    $VPGs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’vpgs’) -Headers $ZertoSession #gathering VPGs active on this ZVM
    $ProtectedVMs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’vms’) -Headers $ZertoSession #gathering VMs which are protected
    $UnprotectedVMs = Invoke-RestMethod -Method Get -Uri ($ZertoRestURL+’virtualizationsites/’+$SiteInfo.SiteIdentifier+’/vms’) -Headers $ZertoSession #VMs which are not protected

    #if you want to output the contents of UnProtectedVms variable you can use the below command;
    #$UnProtectedVMs | select VMname | export-csv -file C:\unprotectedvms.csv

    Thank you so very much for the script bu this script will find all the unprotected VMs running on a particular ZVM. My query is a little different. I want to run a script against a text file to find out which servers are protected under Zerto and which not and generate a csv file. Please advise. Thanks

You must be logged in to create new topics. Click here to login