Solved

Script Basics


Someone can share basic information for learn scripting with nutanix?
icon

Best answer by Johann35 28 May 2018, 16:59

hi,

you can use powershell and acli to create scripts.

Doc powerhell : https://portal.nutanix.com/#/page/docs/details?targetId=API-Ref-AOS-v55:PowerShell-Cmdlets-Reference

Exemple : http://blog.myvirtualvision.com/2016/01/13/nutanix-ahv-creating-a-new-vm-using-powershell/

to use acli, you need just connection ssh on CVM

View original

2 replies

Badge
hi,

you can use powershell and acli to create scripts.

Doc powerhell : https://portal.nutanix.com/#/page/docs/details?targetId=API-Ref-AOS-v55:PowerShell-Cmdlets-Reference

Exemple : http://blog.myvirtualvision.com/2016/01/13/nutanix-ahv-creating-a-new-vm-using-powershell/

to use acli, you need just connection ssh on CVM
Userlevel 2

This is to get Nutanix VM Inventory using powershell



[CmdletBinding(SupportsShouldProcess = $False, ConfirmImpact = "None") ]
Param(
[Parameter(Mandatory = $true)]
[Alias('IP')] [string] $nxIP,
[Parameter(Mandatory = $true)]
[Alias('User')] [string] $nxUser,
[Parameter(Mandatory = $true)]
[Alias('Password')] [Security.SecureString] $nxPassword
)
$loadedsnapins=(Get-PSSnapin -Registered | select name).name
if(!($loadedsnapins.Contains("NutanixCmdletsPSSnapin"))){
Add-PSSnapin -Name NutanixCmdletsPSSnapin
}
$nxServerObj = Connect-NTNXCluster -Server $nxIP -UserName $nxUser -Password $nxPassword -AcceptInvalidSSLCerts
$vms = @(get-ntnxvm)
$FullReport=@()
foreach ($vm in $vms){
$usedspace=0
if(!($vm.nutanixvirtualdiskuuids.count -le 0)){
foreach($UUID in $VM.nutanixVirtualDiskUuids){
$usedspace+=(Get-NTNXVirtualDiskStat -Id $UUID -Metrics controller_user_bytes).values[0]
}
}
if ($usedspace -gt 0){
$usedspace=[math]::round($usedspace /1gb,0)
}
$container= "NA"
if(!($vm.vdiskFilePaths.count -le 0)){
$container = $vm.vdiskFilePaths[0].split('/')[1]
}
$props=[ordered]@{
"VM Name" = $vm.vmName
"Container" = $container
"Protection Domain" = $vm.protectionDomainName
"Host Placement" = $vm.hostName
"Power State" = $vm.powerstate
"Network adapters" = $vm.numNetworkAdapters
"IP Address(es)" = $vm.ipAddresses -join ","
"vCPUs" = $vm.numVCpus
"vRAM (GB)" = [math]::round($vm.memoryCapacityInBytes / 1GB,0)
"Disk Count" = $vm.nutanixVirtualDiskUuids.count
"Provisioned Space (GB)" = [math]::round($vm.diskCapacityInBytes / 1GB,0)
"Used Space (GB)" = $usedspace
}
$Reportobject= New-Object PSObject -Property $props
$fullreport+=$Reportobject
}
$fullreport | Export-Csv -Path ~\Desktop\NutanixVMInventory.csv -NoTypeInformation -UseCulture
Disconnect-NTNXCluster -Servers *

Reply