Book Image

Learning PowerCLI for VMware VSphere

By : Robert van den Nieuwendijk
Book Image

Learning PowerCLI for VMware VSphere

By: Robert van den Nieuwendijk

Overview of this book

Table of Contents (17 chapters)
Learning PowerCLI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Removing a host from the VMware vCenter Server


To remove a host from your vCenter Server inventory, you have to use the Remove-VMHost cmdlet. The Remove-VMHost cmdlet has the following syntax:

Remove-VMHost [-VMHost] <VMHost[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Let's try to remove a host as seen in the following screenshot:

.

The operation failed because the host should have been in maintenance mode or a disconnected state before you could remove it.

So let's put the host in maintenance mode first and then try to remove it:

PowerCLI C:\> $VMHost = Get-VMHost –Name 192.168.0.133
PowerCLI C:\> $VMHost | Set-VMHost -State Maintenance

Name                 ConnectionState PowerState NumCpu CpuUsageMhz
----                 --------------- ---------- ------ -----------
192.168.0.133        Maintenance     PoweredOn       2          41

PowerCLI C:\> $VMHost | Remove-VMHost -Confirm:$false 

The preceding command sets the host in maintenance...