

How to Establish PowerShell Connection to Nutanix and Execute your 1st Query
source link: https://myvirtualcloud.net/how-to-establish-powershell-connection-to-nutanix-and-execute-your-1st-query/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Establish PowerShell Connection to Nutanix and Execute your 1st Query
-
02/20/2014
In my article Nutanix Automation, Policies and the SDDC I discussed how Nutanix exposes all features and functions via REST API, enabling programmatic access to datacenter services within mainstream enterprises.
The current list of features and services that can be fully managed by programmatic access is long and include the following:
- Alerts
- Authconfig
- Cluster
- Containers
- Disks
- Events
- Hosts
- Http proxies
- Protection Domains (Disaster Recovery)
- Remote Sites
- Storage Pools
- Vdisks
- Vstores
In this article I demonstrate how each of these API calls can be used for powerful datacenter automation using PowerShell. Currently PowerShell calls must be done using the Invoke-RestMethod method, but Nutanix will soon be releasing a fully featured PowerShell snap-in, making automation more efficient and easier.
Establishing a connection to PRISM and retrieving cluster information:
[css lang=”plain” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ padlinenumbers=”false” gutter=”true” smarttabs=”true” toolbar=”true” language=”true”]
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
$Uri = "https://10.20.18.10:9440/PrismGateway/services/rest/v1/cluster/"
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))}
$username = "username"
$password = "password"
Invoke-RestMethod -Method Get -Uri $Uri -Headers $Header
[/css]
Results for the Invoke-RestMethod method using PrismGateway/services/rest/v1/cluster. (Click to Enlarge)
Try replacing /cluster with any of the methods listed above and you will start to get the individual properties for VMs, VMDKs, vStores, Storage Pools etc…
This article was first published by Andre Leibovici (@andreleibovici) at myvirtualcloud.net.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK