Remove-SCVMHost

Removes a virtual machine host from VMM.

Description

The Remove-SCVMHost cmdlet removes one or more virtual machine hosts from System Center Virtual Machine Manager (VMM).

The Remove-SCVMHost cmdlet operates as follows:

- HOST SERVER ONLY - If this computer is a Hyper-V host but is not also a
  library server, the host object is removed from the VMM database, and the 
  VMM agent software is uninstalled from the physical host server. 

  If the host is a VMware ESX host or a Citrix XenServer host, the host object 
  is removed from the VMM database. VMM does not install an agent on ESX 
  hosts or XenServer hosts.

- HOST AND LIBRARY SERVER - If this computer is a Hyper-V host and is 
  also a library server, this command removes only the host functionality but 
  leaves the library server feature in place. That is, the host object is 
  removed from the VMM database, but the VMM agent software is not 
  uninstalled from the physical server. The library server object remains in 
  the database.

  If the host is an ESX host, it can function only as a virtual 
  machine host in VMM. It cannot be both a host and a 
  library server. 

- CREDENTIALS - If a Hyper-V host is joined to an 
  Active Directory domain, you must provide credentials for an 
  account with appropriate permissions to remove that host computer 
  from VMM. 

  You do not need to provide Active Directory credentials to remove a 
  perimeter network host, an ESX host or a XenServer host from VMM.

- VIRTUAL MACHINES - When you remove a host, the host is no longer 
  managed by VMM. However, any virtual machines on the host server 
  will not be removed or disassociated from the server. Any running virtual
  machines are not shut down. Although the virtual machines are no longer 
  managed by VMM, they are not affected in any other way. 

- FORCED REMOVAL - You can use the Force parameter with the 
  Remove-SCVMHost cmdlet to remove a virtual machine host from 
  VMM when you do not have appropriate credentials to manage that host or 
  when the VMM server can no longer communicate with that host.

  When you specify the Force parameter, VMM will not ask or check for 
  credentials, nor will VMM attempt to connect to the host and uninstall the 
  VMM agent. Hence, using the Force parameter is recommended only
  when cleaning up stale host records from the VMM database.

This cmdlet returns the object upon success (with the property MarkedForDeletion set to TRUE) or returns an error message upon failure.

For more information about Remove-SCVMHost, type: "Get-Help Remove-SCVMHost -online".

Parameters

VMHost

Required? true
Accept Pipeline Input? true (ByValue)
Position? 0
Specifies a virtual machine host object. VMM supports Hyper-V hosts, VMware ESX hosts, and Citrix XenServer hosts. 

For more information about each type of host, type: "Get-Help Add-SCVMHost -detailed". See the examples for a specific cmdlet to determine how that cmdlet uses this parameter.

Force

Required? true
Accept Pipeline Input? false
Position? named
Forces the operation to complete. 

For example:
- Remove-SCSCVMHost -Force
  Forces the removal of a host object from the VMM database.

- Stop-SCVirtualMachine -Force
  Stops a virtual machine.

Confirm

Required? false
Accept Pipeline Input? false
Position? named
Prompts for confirmation before running the command.

JobVariable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that job progress is tracked and stored in the variable named by this parameter. 

PROTipID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

RunAsynchronously

Required? false
Accept Pipeline Input? false
Position? named
Indicates that the job runs asynchronously so that control returns to the command shell immediately. 

VMHost

Required? true
Accept Pipeline Input? true (ByValue)
Position? 0
Specifies a virtual machine host object. VMM supports Hyper-V hosts, VMware ESX hosts, and Citrix XenServer hosts. 

For more information about each type of host, type: "Get-Help Add-SCVMHost -detailed". See the examples for a specific cmdlet to determine how that cmdlet uses this parameter.

Confirm

Required? false
Accept Pipeline Input? false
Position? named
Prompts for confirmation before running the command.

Credential

Required? false
Accept Pipeline Input? false
Position? named
Specifies a credential object or, for some cmdlets, a Run As account object that contains the user name and password of an account that has permission to perform this action. Or, in the case of Restart-SCJob, has permission to complete a restarted task. 

For more information about the PSCredential object, type: "Get-Help Get-Credential". 
For more information about Run As accounts, type: "Get-Help New-SCRunAsAccount".

JobVariable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that job progress is tracked and stored in the variable named by this parameter. 

PROTipID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

RunAsynchronously

Required? false
Accept Pipeline Input? false
Position? named
Indicates that the job runs asynchronously so that control returns to the command shell immediately. 

Examples

1: Remove a specific domain-joined host from VMM.
PS C:\> $Credential = Get-Credential
PS C:\> $VMHost = Get-SCVMHost -ComputerName "VMHost01"
PS C:\> Remove-SCVMHost -VMHost $VMHost -Credential $Credential -Confirm
The first command uses the Get-Credential cmdlet to prompt you to supply a user name and password and stores the provided credentials in the $Credential variable. The required credentials for this operation are a domain account with administrator rights to remove a Windows-based host server joined to an Active Directory domain from VMM.

The second command gets the host object named VMHost01 and stores the object in the $VMHost variable.

The third command removes the host object stored in $VMHost. As this command is processed, $Credential provides credentials to Remove-VMHost, and the Confirm parameter prompts you to confirm that you do want to remove this host from VMM.
2: Remove all hosts that are not nodes in a host cluster from VMM.
PS C:\> Get-SCVMHost | where {$_.HostCluster -eq $NULL} | where {$_.VirtualizationPlatform -eq "VMwareESX" -or $_.PerimeterNetworkHost -eq 1 -or $_.NonTrustedDomainHost -eq 1} | Remove-SCVMHost -Confirm
PS C:\> $Credential = Get-Credential
PS C:\> Get-VMHost | where {$_.HostCluster -eq $NULL -and $_.VirtualizationPlatform -ne "VMwareESX" -and $_.PerimeterNetworkHost -eq 0 -and $_.NonTrustedDomainHost -eq 0} | Remove-VMHost -Credential $Credential -Confirm
The first command gets all host objects, excludes any hosts that are nodes in a host cluster, selects only those objects that represent VMware ESX hosts, perimeter network hosts, or non-trusted domain hosts, and then removes those objects from VMM if you confirm that you want to remove them. Credentials are not required to remove these hosts.

The second command prompts you to supply a user name and password for an account with permissions to remove domain-joined Windows hosts from VMM and stores your credentials in $Credential.

The last command gets all domain-joined Windows-based host objects that are not part of a host cluster and passes the objects to the Remove-VMHost cmdlet. As this command is processed, $Credential provides your credentials to Remove-VMHost, and the Confirm parameter prompts you to confirm that you do want to remove these hosts from VMM.
3: Remove a specific host that you can no longer access from VMM.
PS C:\> $VMHost = Get-SCVMHost -ComputerName "VMHost03"
PS C:\> Remove-SCVMHost -VMHost $VMHost -Force -Confirm
The first command gets the host object named VMHost03 and stores the object in the $VMHost variable.

The second command switches on the Force parameter to ensure that VMHost03 is removed from the VMM database. Credentials are not needed for this operation. The Confirm parameter prompts you to confirm that you do want to remove this host.

NOTE:  You can use the Force parameter to remove a host from VMM when you do not have the credentials for that host or when the VMM server can no longer communicate with that host.

See Also