Share via


Remove-SCVirtualMachine

Remove-SCVirtualMachine

Removes a virtual machine object from VMM.

Syntax

Parameter Set: Default
Remove-SCVirtualMachine [-VM] <VM> [-Force] [-JobVariable <String> ] [-OnBehalfOfUser <System.String> ] [-OnBehalfOfUserRole <Microsoft.SystemCenter.VirtualMachineManager.UserRole> ] [-PROTipID <Guid]> ] [-RunAsynchronously] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The Remove-SCVirtualMachine cmdlet removes a virtual machine object deployed on a host or stored on a 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.

When used with the Force parameter, Remove-SCVirtualMachine only deletes the virtual machine from the VMM database. It does not delete the virtual machine itself.

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

Parameters

-Force

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.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-JobVariable<String>

Specifies that job progress is tracked and stored in the variable named by this parameter.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-OnBehalfOfUser<System.String>

For example:

- Remove-SCSCVMHost -Force

Forces the removal of a host object from the VMM database.

- Stop-SCVirtualMachine -Force

Stops a virtual machine.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-OnBehalfOfUserRole<Microsoft.SystemCenter.VirtualMachineManager.UserRole>

For example:

- Remove-SCSCVMHost -Force

Forces the removal of a host object from the VMM database.

- Stop-SCVirtualMachine -Force

Stops a virtual machine.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PROTipID<Guid]>

Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-RunAsynchronously

Indicates that the job runs asynchronously so that control returns to the command shell immediately.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-VM<VM>

Specifies a virtual machine object.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

Notes

  • This cmdlet requires a VMM virtual machine object, which can be retrieved by using the Get-SCVirtualMachine cmdlet.

Examples

Example 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.

PS C:\> $VM = Get-SCVirtualMachine -VMMServer "VMMServer01.Contoso.com" | where { $_.VMHost.Name -eq "VMHost01.Contoso.com" -and $_.Name -eq "VM01" }
PS C:\> Remove-SCVirtualMachine -VM $VM

Example 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.

PS C:\> $VMs = @(Get-SCVirtualMachine -VMMServer "VMMServer01.Contoso.com" | where { $_.Name -Match "VM0" } )
PS C:\> $VMs | Remove-SCVirtualMachine

Example Example 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 then 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.

PS C:\> $VM = Get-SCVirtualMachine -VMMServer "VMMServer1.Contoso.com" | where { $_.LibraryServer.Name -eq "LibraryServer01.Contoso.com" -and $_.Name -eq "VM02" }
PS C:\> Remove-SCVirtualMachine -VM $VM

Example 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 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. That cmdlet 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.

PS C:\> $VMs = Get-SCVirtualMachine -VMMServer "VMMServer01.Contoso.com" | where { $_.LibraryServer.Name -eq "LibraryServer01.Contoso.com" -and $_.Name -match "VM0" }
PS C:\> $VMs | Remove-SCVirtualMachine -Confirm

Get-SCVirtualMachine

Move-SCVirtualMachine

New-SCVirtualMachine

Read-SCVirtualMachine

Repair-SCVirtualMachine

Resume-SCVirtualMachine

Save-SCVirtualMachine

Set-SCVirtualMachine

Start-SCVirtualMachine

Stop-SCVirtualMachine

Suspend-SCVirtualMachine