The transition to NetApp MS Azure AD B2C is complete. If you missed the pre-registration, you will be invited to register at next log in.
Please note that access to your NetApp data may take up to 1 hour.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

VMware Solutions Discussions

Snapcenter vshpere plugin 4.5 - powershell

Nirsh

Dear team,

 

I'm trying to generate a token for api queries with powershell, but can't find the right way to do it...

 

How can I generate a token with powrrshell or create a permanent token?

 

 

2 REPLIES 2

TonyPatton

This is how I did it, not necessarily the best or tidiest way.  I was trying to learn how to do REST APIs in PowerShell, so it's probably a mixture of multiple methods.  I never did go back and finish the script I was writing (for backup reports).

 

$RESTAPIServer = "<snapcenter appliance fqdn/ip>:8144"

# Get credentials
try {
    $credentials = Import-Clixml <file with encrypted credentials>.xml -ErrorAction:Stop
} catch {
    write-host "Could not open credentials." -ForegroundColor Red
    exit (1)
}
$REST_API_User = $credentials.UserName
$REST_API_Password = $credentials.GetNetworkCredential().Password

$loginRequest = @{
    username = $REST_API_User
    password = $REST_API_Password
} | ConvertTo-Json

# Set REST authentication headers
$baseURL = "https://" + $RESTAPIServer + "/api/4.1"
$SnapcenterSessionURL = $baseURL + "/auth/login"
$Type = "application/json"

$params = @{
    Uri = $SnapcenterSessionURL
    Body = $loginRequest
    ContentType = 'application/json'
    Method = 'POST'
}

$authResponse = Invoke-RestMethod @params
if ($authResponse.statusCode -eq 200) {
    write-host "Authentication successful"
    $authToken = $authResponse.response.token
}

 

The credentials are encrypted in an XML file, only decryptable by the account & on the machine that they were encrypted on.

aladd

What kind of queries are you attempting to run?

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public