Skip to content
Branch: master
Find file History
Latest commit 3fec3b4 May 23, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
addRemoteCluster 2019-04-10 Apr 11, 2019
agentVersions 2019-04-10 Apr 11, 2019
archiveOldSnapshots 2019-04-10 Apr 11, 2019
backupNow 05-04-2019 May 4, 2019
backupValidationTest 2019-04-10 Apr 11, 2019
cloneDRView 2019-05-23 May 23, 2019
cloneSQL
cloneView 2019-04-10 Apr 11, 2019
cohesity-api
cohesityCluster
createProtectionPolicy 2019-04-10 Apr 11, 2019
createVMProtectionJob 2019-04-10 Apr 11, 2019
deployFieldRack 2019-05-23 May 23, 2019
deployVE 2019-04-30 Apr 30, 2019
deployWindowsAgents 2019-04-10 Apr 10, 2019
destroyClone 2019-04-17 Apr 17, 2019
expireArchivedSnapshots 2019-04-10 Apr 11, 2019
expireOldArchives 2019-04-10 Apr 11, 2019
expireOldSnaps 2019-04-10 Apr 11, 2019
expungeDataSpillage 2019-04-10 Apr 11, 2019
expungeVM 2019-04-10 Apr 11, 2019
fixRedundantProtection 2019-04-12 Apr 12, 2019
getStorageGrowth
instantVolumeMount 2019-04-10 Apr 11, 2019
jobRunStats
listUsersAndGroups
monitorArchiveTasks 2019-04-10 Apr 11, 2019
monitorReplicationTasks 2019-04-16 Apr 16, 2019
netappPathFilters 2019-04-10 Apr 11, 2019
new-PhysicalSource 2019-04-10 Apr 11, 2019
objectRecoveryPoints 2019-04-24 Apr 24, 2019
protectIsilonShares 2019-04-10 Apr 11, 2019
protectPhysicalLinux
protectPhysicalWindows 2019-04-10 Apr 11, 2019
protectVM 2019-04-10 Apr 11, 2019
protectView 2019-04-10 Apr 11, 2019
protectViewList 2019-04-10 Apr 11, 2019
protectedBy 2019-04-10 Apr 11, 2019
recoverNAS 2019-04-10 Apr 11, 2019
recoverVMJob 2019-04-10 Apr 11, 2019
recoveryPoints 2019-04-10 Apr 11, 2019
reduceSnapshotRetention 2019-05-10 May 10, 2019
redundantProtectionReport 2019-04-10 Apr 11, 2019
refreshSource 2019-04-10 Apr 11, 2019
replicateOldSnapshots 2019-05-22 May 22, 2019
restoreSQL
runStats 2019-04-10 Apr 11, 2019
runningJobs 2019-04-15 Apr 15, 2019
summaryReport 2019-04-12 Apr 12, 2019
unprotectVM 2019-04-10 Apr 11, 2019
user_scripts 2019-04-10 Apr 11, 2019
LICENSE.txt 2019-04-25 Apr 25, 2019
README.md 2019-04-15 Apr 15, 2019

README.md

Cohesity PowerShell Scripts

Warning: this code is provided on a best effort basis and is not in any way officially supported or sanctioned by Cohesity. The code is intentionally kept simple to retain value as example code. The code in this repository is provided as-is and the author accepts no liability for damages resulting from its use.

This repository contains many examples of how to automate Cohesity using PowerShell. Common to each example is a function library that makes it easy to authenticate and make api calls. Below are details of this library.

Function library - cohesity-api.ps1

The function library, cohesity-api.ps1 provides a suite of functions to make it easier to use the Cohesity API. To use the library, we can source (or dot) the library within a PowerShell session or within a script, like so:

. ./cohesity-api.ps1

notice the extra dot in the command above. That syntax loads the contents of cohesity-api.ps1 into the current session or script. After sourcing the library, we can start using its functions.

Authentication

apiauth -vip mycluster -username myusername -domain mydomain.net

This command authenticates with the cluster and retrieves an access token for use with subsequent api calls. When the command is run, the user is prompted for their password, and the password will be stored, encrypted, so that scripts can be run unattended, without being prompted for the password again.

If the user's password is changed in Active Directory or in Cohesity, the stored password can be updated using the -updatepassword parameter, for example:

apiauth -vip mycluster -username myusername -domain mydomain.net -updatepassword

apiauth supports the following parameters:

  • -vip: FQDN or IP Address of the Cohesity cluster to connect to
  • -username: username to connect to Cohesity
  • -domain: (optional) Active Directory domain name of user (defaults to local)
  • -prompt: (optional) prompt for password and do not store it (default is to use stored password)
  • -updatepassword: (optional) prompt for password and overwrite the stored password
  • -quiet: (optional) by default a successfull authentication will report Connected!

Making API Calls

Once authenticated, we can make api calls:

$jobs = api get protectionJobs
$jobs | ft

   id name              environment    policyId                            viewBoxId parentSourceId sourceIds            sta
                                                                                                                         rtT
                                                                                                                         ime
   -- ----              -----------    --------                            --------- -------------- ---------            ---
    7 VM Backup         kVMware        770535285385794:1544976774290:5             5              1 {29, 30, 1757}       @{h
   12 Infrastructure    kVMware        770535285385794:1544976774290:5             5              1 {121, 36, 39, 33...} @{h
   35 Oracle Adapter    kOracle        770535285385794:1544976774290:377           5             64 {61}                 @{h
 6222 File-Based Backup kPhysicalFiles 770535285385794:1544976774290:32789         5             60 {98}                 @{h
 8028 SQL Backup        kSQL           770535285385794:1544976774290:377           5             46 {31}                 @{h
31495 Generic NAS       kGenericNas    770535285385794:1544976774290:25            5             85 {1759}               @{h
32207 GarrisonToVE2     kVMware        770535285385794:1544976774290:32206         5              1 {1708, 1709}         @{h
32392 CentOS3           kPhysical      770535285385794:1544976774290:5             5             60 {98}                 @{h
32431 VE2toGarrison     kVMware        698796861248052:1544906007391:10772         5           1718 {1719, 1720}         @{h
32793 Scripts Backup    kView          770535285385794:1544976774290:32206         5            102 {116}                @{h
35465 RMAN Backup       kPuppeteer     770535285385794:1544976774290:25            5            102 {1741}               @{h
39282 Ubuntu            kPhysical      770535285385794:1544976774290:25            5             60 {1755}               @{h
51831 NetAppJob         kNetapp        770535285385794:1544976774290:25            5           1760 {1761}               @{h
54524 CloudSpin         kVMware        770535285385794:1544976774290:25            5              1 {2111}               @{h

The api function supports the following parameters:

  • -method: get, post, put, or delete
  • -url: see below for details
  • -data: (optional) data structure for posts and puts, see below

The url parameter accepts the tail of the api endpoint url. For example, in the example above, the full url is https://mycluster/irisservices/api/v1/public/protectionJobs but the api function only requires the protectionJobs portion of the url.

For non-public api calls, include a leading slash, e.g. api get /backupjobs

The data parameter accepts a nested hash-table of parameters, which are converted to JSON and sent allow with post or put api calls. For example:

$jobdata = @{
   'runType' = "kRegular"
}

Please review the example scripts for data structures that are appropriate for various workflows.

Date Functions

Cohesity stores datetimes in UNIX microseconds, which is the number of microseconds since midnight, January 1st, 1970. cohesit-api.ps1 provides several functions to handle this date format.

dateToUsecs '2019-04-15 13:20:15'
1555348815000000

usecsToDate 1555348815000000
Monday, April 15, 2019 1:20:15 PM

timeAgo 1 month
1552714478000000

usecsToDate 1552714478000000
Saturday, March 16, 2019 1:34:38 AM

timeAgo 1 week
1554737702000000

usecsToDate 1554737702000000
Monday, April 8, 2019 11:35:02 AM
You can’t perform that action at this time.