Update VM Prism Central VM Category (Powershell)

December 23, 2021

by David Teague

Intended Audience Level: Beginner/Intro

Code Sample Type: Complete Script

Nutanix Technologies: Prism Central

Minimum Product Version: 5.17

Script/Code Language: PowerShell

REST API Sample? Yes

REST API Version: v3

Python script for use with Nutanix Era. Provisions Linux-based database engines, to call X-Play playbook that set VM categories in Prism Central.

Code Sample Details

Note this section may be empty, if additional code sample details are not available.

Python script for use with Nutanix Era. Provisions Linux-based database engines, to call X-Play playbook that set VM categories in Prism Central.

To use update the below fields with your environments info.

  • Username and password that as access to Prism Central.
    • $user = youruser
    • $password = yourpassword
  • Valid ip address or FQDN for Prism Central
    • $pcaddress = yourpcaddress
  • Webhook ID copied from X-Play playbook that sets catagory
    • webhookid = yourwebhookid
#Change user and password to vaild user 
$user = "youruser"
$password = "yourpassword" 
#Change pcadderss to ipaddress to fqdn of your prism central
$pcaddress = "yourpcaddress"
#Put your webhook_id from playbook
$webhookid = "yourwebhookid"

#Do not change anything after this comment
$auth = "$user" + ':' + "$password"
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$authorizationInfo = [System.Convert]::ToBase64String($Encoded)
$hostname = "$ENV:COMPUTERNAME"
$service = "https://$pcaddress`:9440/api/nutanix/v3/action_rules/trigger"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Basic $($authorizationInfo)")
$headers.Add("Content-Type", "application/json")
$body = "{`n  `"trigger_type`": `"incoming_webhook_trigger`",`n  `"trigger_instance_list`": 
         [{`n    `"webhook_id`": `"$webhookid`",`n    `"string1`": `"$hostname`"`n  }]`n}"

$response = Invoke-RestMethod -Uri $service -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

# These code samples are intended as a standalone examples.  Subject to licensing restrictions defined on Nutanix.dev, 
# these can be downloaded, copied and/or modified in any way you see fit.  
# Please be aware that all public code samples provided by Nutanix are unofficial in nature, 
# are provided as examples only, are unsupported and 
# will need to be heavily scrutinized and potentially modified before they can be used in a production environment.  
# All such code samples are provided on an as-is basis, 
# and Nutanix expressly disclaims all warranties, express or implied.  
# All code samples are © Nutanix, Inc., and are provided as-is under the MIT license (https://opensource.org/licenses/MIT).