search
top

Retrieving Isilon Share Information with RESTful API and PowerShell

Introduction

In an earlier post we covered using RESTful API calls to EMC Isilon to retrieve quota data. In this post we will make the same calls but gather data on SMB / CIFS Shares for screen output as well and optional CSV output. We will also look at the options to gather for different zones as well.

Prerequisites

To be able to execute RESTful API calls to Isilon you will need to create an account and add the appropriate roles. For GET operations a read-only account is all that you will need. For this post we will create a local group and grant Platform API and SMB read-only roles.

The Code

So now lets get down to the meat of the post and the code we need to execute the RESTful API calls in PowerShell for Isilon.

<# 
.SYNOPSIS 
This script will Retrieve SMB Shares from Isilon using RestfulAPI.

.DESCRIPTION 
This script will Retrieve SMB Shares from Isilon using RestfulAPI.

.NOTES 
File Name : getisilonshares.ps1
Author : Me
Version : 1.0 (July 10, 2018 )

.OUTPUTS 
Screen Output. can be modified to save to csv 

.EXAMPLE 
C:\PS> .\getisilonshares.ps1 

#>

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

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

# create Uri
$baseurl = 'https://xxx.xxx.xxx.xxx:8080' 
$resourceurl = "/platform/1/protocols/smb/shares?zone=System"
$uri = $baseurl + $resourceurl

# Get share information but output only name, path and description
$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

$ISIObject.shares | Select name,path,description

 

Let’s take a deeper look into the code example what it is doing. The first part of the script is setting the security to be able to connect to your Isilon array. This code is not original, I found this at code from blogs.msdn.com. Just copy and paste this section and change the username and password. This will work for any other RESTful API in PowerShell using Basic Authentication.

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

$username = 'root'
$password = 'passw0rd'
$EncodedAuthorization = [System.Text.Encoding]::UTF8.GetBytes($username + ':' + $password)
$EncodedPassword = [System.Convert]::ToBase64String($EncodedAuthorization)
$headers = @{"Authorization"="Basic $($EncodedPassword)"}

Next section of the code we will setup our URI (Uniform Resource Identifier).  we will identify three variables called $baseurl, $resourceurl and $uri. The $baseurl is the https ip address of the Isilon node you want to run the query against. For the $resourceurl variable we will be using the /platform/1/protocols/smb/shares?zone=System resource path. Note: using this resource path will only display the system zone shares, by changing the resource path to /platform/1/protocols/smb/shares?zone=NewZone you can change to grab data from other zones on your Isilon.  You can get a list of all available resource available from EMC RestfulAPI documentation for Isilon. The final $uri is the combining of the two previous variables.

# create Uri
$baseurl = 'https://xxx.xxx.xxx.xxx:8080' 
$resourceurl = "/platform/1/protocols/smb/shares?zone=System"
$uri = $baseurl + $resourceurl

Next section of the code we are going to create an object and make a Invoke-RestMethod cmdlet and GET action using security for authentication.

# Get share information but output only name, path and description
$ISIObject = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

Now we are ready to get the output.

$ISIObject.shares | Select name,path,description

Sample script output

psisilonsmb

There are more fields available for output. By not adding the select statement we will get the full output available.

access_based_enumeration : False
access_based_enumeration_root_only : False
allow_delete_readonly : False
allow_execute_always : False
allow_variable_expansion : False
auto_create_directory : False
browsable : True
change_notify : norecurse
create_permissions : default acl
csc_policy : manual
description : Onbase SMB share
directory_create_mask : 448
directory_create_mode : 0
file_create_mask : 448
file_create_mode : 64
hide_dot_files : False
host_acl : {}
id : onbase
impersonate_guest : never
impersonate_user : 
inheritable_path_acl : True
mangle_byte_start : 60672
mangle_map : {0x01-0x1F:-1, 0x22:-1, 0x2A:-1, 0x3A:-1...}
name : onbase
ntfs_acl_support : True
oplocks : True
path : /ifs/GAFRI/Onbase
permissions : {@{permission=full; permission_type=allow; trustee=}, @{permission=full; permission_type=allow; trustee=}, @{permission=full; 
permission_type=allow; trustee=}, @{permission=full; permission_type=allow; trustee=}}
run_as_root : {}
strict_flush : True
strict_locking : False
zid : 2

From the available output we can add much more to the output. All you have to do is to add the fields to the select statement.

Conclusion

So we have explored making a basic Restful API call to Isilon to get specific SMB/CIFS export information. You can also change the output by exploring the different fields available from the output.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top