The Remove-SCVirtualMachine cmdlet removes a virtual machine object deployed on a host or stored on a System Center Virtual Machine Manager (VMM) library server.
Remove-SCVirtualMachine deletes the virtual machine record from the VMM database, deletes all files associated with the virtual machine, and removes the virtual machine from the host on which it is deployed or from the library server on which it is stored.
If a folder on a host was created for this virtual machine by VMM (rather than by Hyper-V or VMware) and if that folder contains no other virtual machines or other data, you can use the file system to delete the folder after you have removed the virtual machine.
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-SCVirtualMachine, type: "Get-Help Remove-SCVirtualMachine -online".
Parameters
VM
Required?
true
Accept Pipeline Input?
true (ByValue)
Position?
0
Specifies a virtual machine object.
Confirm
Required?
false
Accept Pipeline Input?
false
Position?
named
Prompts for confirmation before running the command.
Force
Required?
false
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.
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.
Requires a VMM virtual machine object, which can be retrieved by using the Get-SCVirtualMachine cmdlet.
Examples
1: Remove a specific virtual machine
deployed on a host.
The first command gets the virtual machine object named VM01 deployed on VMHost01 and then stores the virtual machine object in the $VM variable.
The second command removes the object stored in $VM and deletes the corresponding virtual machine files from the file system on its host.
2: Remove all virtual machines with
names that include a specific string.
The first command gets all virtual machine objects deployed on any host whose name includes the string "VM0" and then stores these virtual machine objects in the array named $VMs.
The second command removes each virtual machine object in the $VMs array and deletes the corresponding virtual machine files from the file system on each host.
3: Remove a specific virtual machine
stored on a VMM library server.
The first command gets the object that represents the virtual machine named VM03 (which is stored on the library server named FileServer01) and stores the virtual machine object in $VM. This example assumes that only one virtual machine named VM03 exists.
The second command removes the object that represents VM03 from the library and deletes the corresponding virtual machine files from the file system on the library server.
4: Remove multiple stored virtual
machines from the VMM library.
The first command gets all virtual machine objects whose names include the string "VM0" and that are stored stored on LibraryServer01. The command then stores the virtual machine objects in the array named $VMs.
The second command passes each virtual machine object stored in $VMs to the Remove-SCVirtualMachine cmdlet, which removes each object from the library and deletes the corresponding virtual machine files from the file system on the library server. The Confirm parameter prompts you to confirm whether you want to delete each of these virtual machines.