Automating ZVR with PowerShell and REST APIs …

Automating Zerto with PowerShell and REST APIs

Version 4.0 August 2022

Legal Disclaimer

Copyright ? 2022, Zerto Ltd. All rights reserved. Information in this document is confidential and subject to change without notice and does not represent a commitment on the part of Zerto Ltd. Zerto Ltd. does not assume responsibility for any printing errors that may appear in this document. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information storage and retrieval systems, for any purpose other than the purchaser's personal use, without the prior written permission of Zerto Ltd. All other marks and names mentioned herein may be trademarks of their respective companies. The scripts are provided by example only and are not supported under any Zerto support program or service. All examples and scripts are provided "as-is" without warranty of any kind. This includes encrypting passwords. In all the examples provided in this document the passwords are stored using plain text within your PowerShell scripts. This is often against company policy and so is only done for ease of testing and there are multiple ways to remove the use of plain text passwords. The author and Zerto further disclaim all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. In no event shall Zerto, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if the author or Zerto been advised of the possibility of such damages. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you.

Automating Zerto with PowerShell and REST APIs

1 of 19

Table of Contents

LEGAL DISCLAIMER................................................................................................................................. 1 INTRODUCTION ...................................................................................................................................... 3

What is PowerShell? ...................................................................................................... 3 What is a cmdlet?........................................................................................................... 3 Understanding Variables & Arrays ................................................................................ 3 What are REST APIs? ...................................................................................................... 4 SCRIPTING BEST PRACTICES ............................................................................................................... 4 PREREQUISITES ...................................................................................................................................... 4 RESOURCES ............................................................................................................................................. 5 API Documentation ....................................................................................................... 5 Zerto PowerShell Cmdlet Documentation ................................................................... 5 GETTING STARTED ................................................................................................................................. 5 Connecting to Zerto APIs Traditionally ........................................................................ 5 Downloading Zerto cmdlets.......................................................................................... 5 ZERTO POWERSHELL SCRIPTS ........................................................................................................... 6 CONNECT TO THE ZERTO VIRTUAL MANAGER (ZVM) .................................................................... 6 Deploying Virtual Replication Appliances (VRAs) ......................................................... 7 DEPLOYING VIRTUAL PROTECTION GROUPS (VPGS)................................................................... 10 FAILOVER TEST SCRIPT ....................................................................................................................... 16 ARCHIVED REFERENCES ..................................................................................................................... 18

Automating Zerto with PowerShell and REST APIs

2 of 19

Introduction

Zerto, a Hewlett Packard Enterprise company, empowers customers to run an always-on business by simplifying the protection, recovery, and mobility of on-premises and cloud applications. Zerto's cloud data management and protection solution eliminate the risks and complexity of modernization and cloud adoption across private, public, and hybrid deployments. The simple, software-only solution uses continuous data protection at scale to converge disaster recovery, backup, and data mobility. Zerto is trusted by over 9,500 customers globally and is powering offerings for Microsoft Azure, IBM Cloud, AWS (Amazon Web Services), Google Cloud, Oracle Cloud, and more than 350 managed service providers.

This guide provides an overview of how to utilize PowerShell to start scripting powerful automated disaster recovery procedures using Zerto REST APIs. Doing so enables the reduction of manual processes, scripting installations, integrating with third-party tools, and the realization of the full benefits of software-defined replication and recovery in protecting a virtualized IT infrastructure. This guide is for PowerShell users who may want to implement any of the use cases mentioned:

? Automating virtual machine (VM) protection

? Automating VM protection with vRealize Orchestrator

? Establishing a connection to the Zerto Virtual Machine (ZVM)

? Bulk VRA deployment

? Bulk VPG configuration

? Failover Test

The examples given have been developed to meet the requirements of Zerto cloud and enterprise environments. The font size of the examples given are optimized depending on the maximum line length to enable copying and pasting directly from the PDF into your PowerShell scripts.

What is PowerShell?

PowerShell is a command-line shell and a scripting language all in one. It allows users to run commands on local or remote computers to automate tasks like managing users and automating workflows. By default, PowerShell offers many helpful commands and can increase its capabilities by installing more modules.

What is a cmdlet?

A cmdlet (pronounced "command-let") is a compiled command that runs in PowerShell. These compiled lines of code execute pre-defined functions. For example, the Get-Help core cmdlet to invoke a built-in help system for a developer to troubleshoot the code more efficiently.

Understanding Variables & Arrays

To store data for execution within PowerShell scripts, it is important to use variables and arrays for efficiency. Variables allow a value to be used multiple times and it only needs to be changed once, making editing scripts easier. For ease of use, the same variables will be used in all examples in this document, these are:

$ZertoServer= "192.168.0.31" $ZertoPort= "9669 $ZertoUser= "administrator@lab.local" $ZertoPassword= "Password123!"" $vCenterServer= "192.168.0.31" $vCenterUser= "administrator@lab.local" $vCenterPassword= "Password123!"

Automating Zerto with PowerShell and REST APIs

3 of 19

Arrays are used in many examples in this document. These are used to build tables of data obtained from the APIs and multiple data sources simultaneously. The array is then used to export data to CSVs or to perform multiple actions within the script. Arrays are created line by line with the required values which are then added together. Below as an example of how to create a simple array:

$Value1 = "FirstValue" $Value2 = "SecondValue" $Array = @() $ArrayLine = new-object PSObject $ArrayLine | Add-Member -MemberType NoteProperty -Name "Value1" -Value $Value1 $ArrayLine | Add-Member -MemberType NoteProperty -Name "Value2" -Value $Value2 $Array += $ArrayLine $Array

What are REST APIs? An Application Programming Interface (API) is a set of clearly defined methods of communication between various software components. Representational State Transfer (REST) determines what the API looks like. It is also a set of rules that developers follow when creating an API. Together, a REST API allows you to query an API via a URL and request a response or send a change to the API via a URL and modify the data.

The REST APIs utilized in the examples are all included within the Zerto Virtual Manager (ZVM) documentation set. The document does not intend to give examples for all the available APIs. Its purpose is to give examples of the most requested use cases and share both information and knowledge on how to customize and create automation scripts.

Scripting Best Practices

Scripting and automating tasks in a production environment can introduce an element of risk if care is not taken to ensure the scripts have been tested. To mitigate this risk, follow the below best practices:

1. Use test VMs where applicable for initial testing 2. Use a demo lab or separate vSphere environment if available for testing 3. Test scripts using PowerShell ISE to aid with troubleshooting before scheduling a script 4. Use transcripts to maintain audit trails and aid with troubleshooting 5. Create descriptive comments throughout scripts to make it easier to understand and edit 6. Use version control, e.g. with git, on scripts with last known good configurations 7. Manage and schedule scripts from a central server 8. Document scripts and automated processes 9. Ensure IT teams know how to enable and disable scripts

Prerequisites

All the example scripts given in this document share a common set of minimum requirements. These are:

? Zerto Virtual Manager (ZVM) is deployed

o ZVM Server Name, username, and password with permission is used to access its API

? Network connectivity to the ZVM

? Access permission to write in and create the directory specified for logging, or manually create the directory in advance

Automating Zerto with PowerShell and REST APIs

4 of 19

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download