I managed to do this “the hard way” by using REST API.
Thanks to:
Failing to execute Set-NTNXVMPowerState from PoSH Script - access denied
leepryor / Nutanix_Powershell
$Uri = "https://<PrismClusterElement>:9440/api/nutanix/v2.0/vms/<AHV VMid>/nics/<AHV VM NIC MAC Address>"
$RESTAPIUser = $MyCreds.UserName
$RESTAPIPassword = $MyCreds.GetNetworkCredential().Password
$Header = @{"Authorization" = "Basic "+sSystem.Convert]::ToBase64String(tSystem.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+":"+$RESTAPIPassword ))}
$ContentType = "application/json"
$Body = '
{
"nic_spec": {
"is_connected": true,
"network_uuid": "<AHV Network UUID>"
}
}
'
Invoke-RestMethod -Uri $Uri -Body $Body -ContentType $ContentType -Headers $Header -Method "PUT"
It then returns the task_uuid and you can see in the web GUI the status of the task.
Another big help was the “REST API Explorer Live!” in the web GUI.
I can use this for now but I would really like to see a “Set-NTNXVMNIC” cmdlet in future releases.
-TimG
I did figure out that I wasn’t actually deleting the VMNIC like I thought. The -Nicid parameter is actually looking for the MAC address. Once I used that then I could delete the NIC. Of course, when you remove the NIC and then add a new one to it then that changes the MAC address.
I tried removing the NIC and then adding the NIC with “isConnected = False” in the VMNicSpecDTO but it still started up as connected.