In the previous blog, we discussed the steps Cohesity’s API Integrations team is taking to encourage more engagement from developers. They include maintaining a Developer Portal, a Contribution Guide, issue templates, code samples to get started, and awesome documentation. In this blog, we explore the PowerShell SDK and some of the steps we took to make it more developer-friendly and easy to use.
In the early stages of our PowerShell SDK development, we used C# to write cmdlets. With PowerShell’s ability to make REST API calls using the Invoke-RestMethod and Invoke-WebRequest calls, we decided to leverage it to write cmdlets using PowerShell script itself, helping people who are already familiar with PowerShell scripting. Using a script to write cmdlets allows you to reuse the common components of the script when writing a new cmdlet. For example, there is a script that takes Cohesity cluster details and establishes a connection using API calls — now, this script can be imported by other scripts for connecting to a cluster and/or making API calls.
To make it even easier for anyone to write script-based cmdlets, we have come up with a Template Generator. Using this, you can generate a script skeleton by answering simple questions like the actionType (like GET or PUT) and Feature Name. Once you provide the script with the responses, it generates a script that you can edit to add your cluster details and feature implementation code.
This script makes it much easier to write your own cmdlets! What’s more, once you have tested it, you can contribute it back to the GitHub repo. Once we review and pass it, it’ll be published for all!
To make logging and debugging easier for Cohesity PowerShell cmdlets, the SDK provides users a way to set various cmdlet configurations using the Set-CohesityCmdletConfig cmdlet. It provides options to Log the output, set Log Header, Define Error Action, Set log output location, and more.
This custom configuration option gives developers great flexibility to log cmdlet actions, debug, and fix issues.
Cohesity cmdlet Set-CohesityCmdletConfig Gives Developers Flexibility
One of the many powerful features in our PowerShell GitHub repo is the collection of sample workflows . Along with simple examples that focus on a single cmdlet, we also included end-to-end workflows like the VMware workflow, where we use the cmdlets to perform protection and recovery of VMware objects. Such end-to-end workflows serve as good examples for developers to reuse and edit for automation and for creating entirely new cmdlets.
Our other goal for the sample workflows is to encourage developers to write their own workflows and then share them with the community to build several workflows that cover many use cases.
Get started with these helpful resources:
In an upcoming blog, we’ll walk you through the most used Cohesity workflow using the PowerShell SDK. Stay tuned. Until then, happy coding!