Removing Virtual Machine Hosts

Removes the specified Virtual Machine Host object(s).


Examples:


Hint: The execution of these examples requires a connected PowerShell drive.


This command deletes the Virtual Machine Host "ESX22" in the context "Virtual Environments\ESXServers" using the Remove-EmdbVirtualHost cmdlet:


Remove-EmdbVirtualHost "emdb:\rootDSE\Managed Virtual Environments\ESXServer\ESX22"


While the code snippet below deletes the same Virtual Machine Host in the current context:


cd "emdb:\rootDSE\Managed Virtual Environments\ESXServer\"

Remove-EmdbVirtualHost "ESX22"


Remove the VM-Host "ESX21" from the context "Virtual Environments\ESXServers" using the method Delete():


$MyVMHost = Get-EmdbVirtualHost "emdb:\rootDSE\Managed Virtual Environments\ESXServers\ESX21"

$MyVMHost.Delete()


Remove the VM-Host "ESX22" from the context Virtual Environments\ESXServers" using the cmdlet Remove-Item:


Remove-Item "emdb:\rootDSE\Managed Virtual Environments\ESXServers\ESX22"


Hint: Alternatively the alias DEL can be used to remove Virtual Machine Host objects.


Starting with PSX 3.1 there was a new option implemented when retrieving Virtual Machine Host objects. When specifying the SingleItemExpected-switch it is expected, that none or exactly one object is contained in the result. If the retrieval returns more than one object, an error is raised that can be caught and handled in scripts.