how to I remove host from get-view?
I looked at
get-view -viewtype 'hostsystem' -property 'name' -filter @{"Name" = "esxhost"} | gm
but did not find the task there
Name MemberType Definition
---- ---------- ----------
AcquireCimServicesTicket Method VMware.Vim.HostServiceTicket Acq...
Destroy Method void Destroy()
Destroy_Task Method VMware.Vim.ManagedObjectReferenc...
DisconnectHost Method void DisconnectHost()
DisconnectHost_Task Method VMware.Vim.ManagedObjectReferenc...
EnterLockdownMode Method void EnterLockdownMode()
EnterMaintenanceMode Method void EnterMaintenanceMode(int ti...
EnterMaintenanceMode_Task Method VMware.Vim.ManagedObjectReferenc...
Equals Method bool Equals(System.Object obj)
ExitLockdownMode Method void ExitLockdownMode()
ExitMaintenanceMode Method void ExitMaintenanceMode(int tim...
ExitMaintenanceMode_Task Method VMware.Vim.ManagedObjectReferenc...
GetAllEventsView Method VMware.Vim.EventHistoryCollector...
GetAllTasksView Method VMware.Vim.TaskHistoryCollector ...
GetEntityOnlyEventsCollectorView Method VMware.Vim.EventHistoryCollector...
GetEntityOnlyTasksCollectorView Method VMware.Vim.TaskHistoryCollector ...
GetEventCollectorView Method VMware.Vim.EventHistoryCollector...
GetHashCode Method int GetHashCode()
GetTaskCollectorView Method VMware.Vim.TaskHistoryCollector ...
GetType Method type GetType()
PowerDownHostToStandBy Method void PowerDownHostToStandBy(int ...
PowerDownHostToStandBy_Task Method VMware.Vim.ManagedObjectReferenc...
PowerUpHostFromStandBy Method void PowerUpHostFromStandBy(int ...
PowerUpHostFromStandBy_Task Method VMware.Vim.ManagedObjectReferenc...
QueryHostConnectionInfo Method VMware.Vim.HostConnectInfo Query...
QueryMemoryOverhead Method long QueryMemoryOverhead(long me...
QueryMemoryOverheadEx Method long QueryMemoryOverheadEx(VMwar...
QueryTpmAttestationReport Method VMware.Vim.HostTpmAttestationRep...
RebootHost Method void RebootHost(bool force)
RebootHost_Task Method VMware.Vim.ManagedObjectReferenc...
ReconfigureHostForDAS Method void ReconfigureHostForDAS()
ReconfigureHostForDAS_Task Method VMware.Vim.ManagedObjectReferenc...
ReconnectHost Method void ReconnectHost(VMware.Vim.Ho...
ReconnectHost_Task Method VMware.Vim.ManagedObjectReferenc...
Reload Method void Reload()
Rename Method void Rename(string newName)
Rename_Task Method VMware.Vim.ManagedObjectReferenc...
RetrieveHardwareUptime Method long RetrieveHardwareUptime()
setCustomValue Method void setCustomValue(string key, ...
SetViewData Method void SetViewData(VMware.Vim.Obje...
ShutdownHost Method void ShutdownHost(bool force)
ShutdownHost_Task Method VMware.Vim.ManagedObjectReferenc...
ToString Method string ToString()
UpdateFlags Method void UpdateFlags(VMware.Vim.Host...
UpdateIpmi Method void UpdateIpmi(VMware.Vim.HostI...
UpdateSystemResources Method void UpdateSystemResources(VMwar...
UpdateSystemSwapConfiguration Method void UpdateSystemSwapConfigurati...
UpdateViewData Method void UpdateViewData(Params strin...
WaitForTask Method System.Object WaitForTask(VMware...
AlarmActionsEnabled Property bool AlarmActionsEnabled {get;}
AvailableField Property VMware.Vim.CustomFieldDef[] Avai...
Capability Property VMware.Vim.HostCapability Capabi...
Client Property VMware.Vim.VimClient Client {get;}
Config Property VMware.Vim.HostConfigInfo Config...
ConfigIssue Property VMware.Vim.Event[] ConfigIssue {...
ConfigManager Property VMware.Vim.HostConfigManager Con...
ConfigStatus Property VMware.Vim.ManagedEntityStatus C...
CustomValue Property VMware.Vim.CustomFieldValue[] Cu...
Datastore Property VMware.Vim.ManagedObjectReferenc...
DatastoreBrowser Property VMware.Vim.ManagedObjectReferenc...
DeclaredAlarmState Property VMware.Vim.AlarmState[] Declared...
DisabledMethod Property string[] DisabledMethod {get;}
EffectiveRole Property int[] EffectiveRole {get;}
Hardware Property VMware.Vim.HostHardwareInfo Hard...
LicensableResource Property VMware.Vim.HostLicensableResourc...
LinkedView Property VMware.Vim.HostSystem_LinkedView...
MoRef Property VMware.Vim.ManagedObjectReferenc...
Name Property string Name {get;}
Network Property VMware.Vim.ManagedObjectReferenc...
OverallStatus Property VMware.Vim.ManagedEntityStatus O...
Parent Property VMware.Vim.ManagedObjectReferenc...
Permission Property VMware.Vim.Permission[] Permissi...
RecentTask Property VMware.Vim.ManagedObjectReferenc...
Runtime Property VMware.Vim.HostRuntimeInfo Runti...
Summary Property VMware.Vim.HostListSummary Summa...
SystemResources Property VMware.Vim.HostSystemResourceInf...
Tag Property VMware.Vim.Tag[] Tag {get;}
TriggeredAlarmState Property VMware.Vim.AlarmState[] Triggere...
Value Property VMware.Vim.CustomFieldValue[] Va...
Vm Property VMware.Vim.ManagedObjectReferenc...
I am trying to disconnect a host from a cluster, remove it and add it back into another vcenter
Have a look at Destroy
I can't test this right now but the privs required to run it on a HostSystem object make it look like its what you're looking for...
Like Craig said use the destroy or destroy_task,
if you want to disconnect it before , use DisconnectHost_Task or DisconnectHost .
This will work, already done it few times.
I cannot get this to work
get-vmhost vmhost | % {
$view = get-view $_.id
$arg = new-object VMware.Vim.HostConnectSpec
$arg.userName = "root"
$arg.password = $password
$arg.force = $true
$view.DisconnectHost()
$view.Destroy_task()
}
But in vcenter I got
The operation is not supported on the object. any idea? I put a start-sleep 10 before the Destroy_task() but it would not let me disconnect and remove host
any idea?
Can you check with 1 host only ?
$vmhost = get-view -viewtype hostsystem -filter @{'name'='YourEsxiName'}
$vmhost.DisconnectHost_Task()
$vmhost.Destroy_Task()
You connect to Virtual center first.
Connect-viserver [name_of_vc] -credential (get-credential)
no same error in vcenter. host got disconnected but the remove host task is not working
I was seeing the same issues, although I was using the vSphere Perl SDK instead of the PowerCLI one. I found this in the Perl API doco for vSphere 6, and I assume PowerCLI mentions the same thing somewhere in its doco for HostSystem.
Invoking destroy on a HostSystem of standalone type throws a NotSupported fault. A standalone HostSystem can be destroyed only by invoking destroy on its parent ComputeResource.
I retrieve the ComputeResource by getting the parent of the HostSystem managed object. It also is named the same as the host (in the case of a standalone host). I can't give you the exact PowerCLI code, but I hope this helps!
That is correct, I use the following code to remove a HostSystem
$hostName = 'MyEsx'
$esx = Get-View -ViewType HostSystem -Filter @{'Name'=$hostName}
$parent = Get-View -Id $esx.Parent
$esx.DisconnectHost()
if($parent -is [VMware.Vim.ClusterComputeResource])
{
$esx.Destroy()
}
elseif($parent -is [VMware.Vim.ComputeResource])
{
$parent.Destroy()
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference