Delen via


Remove-SCVirtualMachine

Removes a virtual machine object from VMM.

Syntax

Default (Default)

Remove-SCVirtualMachine
    [-VM] <VM>
    [-SkipFileRemoval]
    [-Force]
    [-RunAsynchronously]
    [-PROTipID <Guid>]
    [-JobVariable <String>]
    [-WhatIf]
    [-Confirm]
    [-OnBehalfOfUser <String>]
    [-OnBehalfOfUserRole <UserRole>]
    [<CommonParameters>]

Description

The Remove-SCVirtualMachine cmdlet removes a virtual machine object deployed on a host or stored on a Virtual Machine Manager (VMM) library server.

This cmdlet 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, instead of 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.

If you specify the Force parameter, this cmdlet only deletes the virtual machine from the VMM database. It does not delete the virtual machine itself.

This cmdlet returns the object upon success that has a value of $True for the MarkedForDeletion property. If it fails, the cmdlet returns an error message.

Examples

Example 1: Remove a specific virtual machine deployed on a 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

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.

Example 2: Remove all virtual machines with names that include a specific string

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

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.

Example 3: Remove a specific virtual machine stored on a VMM 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

The first command gets the object that represents the virtual machine named VM03, and then stores the virtual machine object in $VM. In this example, 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.

Example 4: Remove multiple stored virtual machines from the VMM library

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

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

Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Force

Indicates that this cmdlet only deletes the virtual machine from the VMM database. It does not delete the virtual machine itself.

Note

For virtual machine deployed using service templates or VMRole, this parameter is ignored and the actual virtual machine also gets deleted.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-JobVariable

Specifies a variable in which job progress is tracked and stored.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-OnBehalfOfUser

Specifies a user name. This cmdlet operates on behalf of the user that this parameter specifies.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-OnBehalfOfUserRole

Specifies a user role. To obtain a user role, use the Get-SCUserRole cmdlet. This cmdlet operates on behalf of the user role that this parameter specifies.

Parameter properties

Type:UserRole
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-PROTipID

Specifies the ID of the Performance and Resource Optimization tip (PRO tip) that triggered this action. This parameter lets you audit PRO tips.

Parameter properties

Type:Guid
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-RunAsynchronously

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SkipFileRemoval

Indicates that this cmdlet does not remove virtual machine related files directly. If you specify this parameter, no attempt is made to delete any files directly.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-VM

Specifies a virtual machine object.

Parameter properties

Type:VM
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

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

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Notes

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