Using SkySync CLI: Surface User Accounts from Disparate Storage Platforms


Would you like insight into your organization’s surface user accounts across multiple on-premise or cloud platforms? Using the SkySync CLI and ReST API, the job can be accomplished quickly and easily.

Using the SkySync CLI Authorization and ReST Endpoints

In this post, we are going to obtain a SkySync Authorization Token via the SkySync CLI and utilize PowerShell’s Invoke-RestMethod to make a request to the SkySync Connections ReST API endpoint for a specific platform. Ready…here we go!


This exercise requires the SkySync CLI. Check out and complete the steps in our previous post, “Introduction to the SkySync CLI” before moving forward.

Let’s see what connections you have available. Execute the command to get a list of the available connections and choose a connection that you would like to interrogate for surface user account information. Make note of the GUID for the connection. We will need that shortly.

skysync-cli connections list

Now, on to the meat-and-potatoes! Let’s export some user account information.

SkySync CLI Authorization

First we will need to obtain the proper Authorization Token to access the SkySync ReST APIs. SkySync encapsulates the messy job of creating an authorization header token with the following commands. The Authorization Token is necessary to make most requests to the SkySync ReST API.

$accessToken= skysync-cli sessions token --output-json=false
$authHeader = @{"Authorization"="Bearer $accessToken";}

SkySync Connection/Accounts ReST EndPoint

Referring to the Endpoint URL below, we will want to update the [machineName] with the name or IP of the SkySync server. This will be the same name or IP you entered in the skysync-cli.json file.  Additionally, update the [connectionId] with the Connection ID or GUID you noted earlier.

Finally, execute the statements and the applicable account information will output to the command line window.

$accountsEndpoint = "http://[machineName]:9090/v1/connections/[connectionId]/accounts?offset=0&limit=1000&fields=all"
$accountsResponse = Invoke-RestMethod $accountsEndpoint -Headers $authHeader
Write-host $accountsResponse.accounts

Awesome, right?

As you can see, with just a few lines of PowerShell script you can call a SkySync ReST Endpoint and output useful information. The SkySync Connector architecture encapsulates disparate APIs and provides a unified front to interact with a multitude of platforms.

Complete Script Example with EndPoint Paging

While the above code slice is nice for our exercise purposes, see below for full implementation of this concept and the additional logic for paging the user account result sets.  While we focused on the Connection Accounts endpoint here, this script pattern forms the basis for many operations that can be accomplished with the SkySync ReST API. Explore our local online API docs at http://[machineName]:9090/api-docs/ and see what else is possible with SkySync!

<# .DESCRIPTION Exports list of name, email, and id of users of a platform connection via SkySync accounts endpoint and cli auth session .INPUTS BaseUrl (url of SkySync + /v1) ConnectionId (id of connection - > skysync-cli connections list)
CSV file in relative directory containing name, email, and id of users
* Script uses the SkySync CLI to obtain Auth Token. Must navigate to path where skysync-cli is available to execute
* cd C:\dev\local\skysync-cli
* To route local endpoint calls from PowerShell through Fiddler for debugging/testing:
* $baseUrl must use machine name and not "localhost"
* uncomment -Proxy 'http://localhost:8888', which is Fiddlers Proxy address
.\'export skysync connection accounts to csv.ps1' http://mymachine:9090/v1 fcfef7e24b164a0ca181cb55b0078d40
[string]$baseUrl = "http://[machine name]:9090/v1",
[string]$connectionId = "[connection_id]"
$offsetValue = 0
$pages = 1
$currentPage = 0
$totalCount = 0
$accounts = @()
#get skysync access token via skysync-cli
$accessToken= skysync-cli sessions token --output-json=false
$authHeader = @{"Authorization"="Bearer $accessToken";}
#call endpoint with paging (endpoint only returns 1000 items at a time)
do {
$accountsEndpoint ="$baseUrl/connections/$connectionId/accounts?offset=$offsetValue&limit=1000&fields=all"
$accountsResponse = Invoke-RestMethod $accountsEndpoint -Headers $authHeader #-Proxy 'http://localhost:8888'
$accounts += $accountsResponse.accounts
$totalCount = $accountsResponse.meta.total_count
if ($totalCount -gt 1000){
$pages = [math]:: Ceiling($totalCount / 1000)
$offsetValue = ($currentPage * 1000)
} while ($pages -ne $currentPage)
$accounts | Select-Object -Property name,email,id | Format-Table
$accounts | Select-Object -Property name,email,id | Export-Csv "accounts_$connectionId.csv" -NoTypeInformation
write-host "$totalCount Total Accounts for Connection $connectionId Successfully Exported to CSV" -ForegroundColor Green