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 virtual machine


In the life cycle of a virtual machine, there comes a time when you may want to remove it. This may be because the application running on the virtual machine is not in use anymore or because the operating system running on the virtual machine is obsolete and you have moved the application to a new server. To remove a virtual machine, you can use the Remove-VM cmdlet, which has the following syntax:

Remove-VM [-DeletePermanently] [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

If you use the –DeletePermanently parameter, the virtual machine will be removed from your vSphere inventory and from the datastores. If you omit the –DeletePermanently parameter, the virtual machine will only be removed from the vSphere inventory. Because the virtual machine's files remain on the datastores, you can register the virtual machine again.

In the following example, we will use the Remove-VM cmdlet to remove...