Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

4631

June 16th, 2014 16:00

Using Powershell to connect to EMC AppSync via REST?

Hello,

This is a question for you developer type people out there.

Since Appsync does not allow any remote scripting I'm trying to dive in using powershell 4.0 and Invoke-RestMethod.  I've read the AppSync 1.6.0 REST API Reference and i'm stuck at the authentication part.

I understand that i have to authenticate to the CAS server and then use that sessionID throughout my use of the script, that's fine.  However, I can't figure out how to connect to the AppSync CAS server properly.

This guy is showing how (in EMC Prosphere) a Powershell user can authenticate using Invoke-Webrequest and get the session variable.

function Get-ProSphereSession {

    param( 

    ## ProSphere virtual machine FQDN

    [string] $psfqdn = "",

    ## ProSphere username

    [string] $username = "appadmin",

    ## ProSphere username

    [string] $password = "Changeme1!"

    )

    #Get a web session variable for the ProSphere instance

    [string] $loginuri = "https://" + $psfqdn + "/cas-server/login"

    $request = Invoke-WebRequest -Uri $loginuri -SessionVariable ps

    #Login to the CAS server

    $form = $request.Forms[0]

    $form.Fields["username"] = $username

    $form.Fields["password"] = $password

    $request = Invoke-WebRequest -Uri $loginuri -WebSession $ps -Method POST -Body $form.Fields

    #Return the authenticated web session variable

    $ps

}

How do I do this for Appsync?

Can you provide me the proper URI and info so I can connect?

Thanks,

Ben

105 Posts

November 13th, 2014 20:00

Here it is, Engineering was nice enough to help me get authentication working.  This script below will authenticate to AppSync and then list the service plans on the AppSync server.

Accessing the XML is pretty easy ($result.feed.entry) but I've not yet tried a POST.  Will take a look at that one.$result.feed.entry

$appsyncServer = 'myServer'

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

string]$LoginUri = "https://"+$appsyncServer+":8444/cas-server/login?TARGET=https://"+$appsyncServer+":8445/appsync/"

$request = Invoke-WebRequest -Uri $LoginUri -SessionVariable session

$request

#Login to the CAS server

$form = $request.Forms[0]

$form.Fields["username"] = 'admin'

$form.Fields["password"] = 'myAppSyncPassword'

$request = Invoke-RestMethod -Uri $LoginUri -WebSession $session -Method POST -Body $form.Fields

# Done with authentication!

[string]$RestUri = "https://"+$appsyncServer+":8445/appsync/rest/types/servicePlan/instances"

#[string]$RestUri = "https://$appsyncServer:8445/appsync/rest/types/servicePlan/instances?application=sql&name=sql silver"

$result = Invoke-RestMethod -Uri $RestUri -WebSession $session -Method GET

# Get familar with XML: https://www.simple-talk.com/sysadmin/powershell/powershell-data-basics-xml/

$result

$result.feed

$result.feed.entry    # Your list of service plans!

14 Posts

April 13th, 2016 12:00

Hi Ben,

Did you have any luck posting to AppSync?

I was trying to create a file system protection service plan but so far no luck.

105 Posts

April 14th, 2016 07:00

I still have not performed any POST operations.  I have been using existing service plans and controlling them with the ESI PowerShell modules.  Unfortunately, there are no CMDLETS to create service plans.

If you get something working with REST please post back to this thread to share with the community!

Ben

82 Posts

April 14th, 2016 11:00

If you are looking to create and modify service plans, please see the following thread...

https://community.emc.com/message/933273

No Events found!

Top