Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Remove-SCVirtualDiskDrive

Updated: September 27, 2012

Applies To: System Center 2012 - Virtual Machine Manager

Remove-SCVirtualDiskDrive

Removes a virtual disk drive object from a virtual machine or from a virtual machine template.

Syntax

Parameter Set: Default
Remove-SCVirtualDiskDrive [-VirtualDiskDrive] <VirtualDiskDrive> [-Force] [-JobGroup <Guid> ] [-JobVariable <String> ] [-PROTipID <Guid> ] [-RunAsynchronously] [-SkipDeleteVHD] [ <CommonParameters>]




Detailed Description

The Remove-SCVirtualDiskDrive cmdlet removes one or more virtual disk drive objects from a virtual machine or from a virtual machine template in a System Center Virtual Machine Manager (VMM) environment.

For more information about Remove-SCVirtualDiskDrive, type: "Get-Help Remove-SCVirtualDiskDrive -online".

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?

true (ByValue)

Accept Wildcard Characters?

false

-JobGroup<Guid>

Specifies an identifier for a series of commands that will run as a set just before the final command that includes the same job group identifier runs.


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

-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

-SkipDeleteVHD

Indicates that the VHD file will not be deleted when the virtual disk drive is removed.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-VirtualDiskDrive<VirtualDiskDrive>

Specifies a virtual disk drive object. You can attach either a virtual hard disk (for a virtual machine on any host) or a pass-through disk (for a virtual machine on a Hyper-V host or an ESX host) to a virtual disk drive object.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters.

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

  • Requires a VMM virtual disk drive object, which can be retrieved by using the Get-SCVirtualDiskDrive cmdlet.

Examples

1: Remove the second virtual disk drive object from the specified virtual machine.

The first command gets the virtual machine object named VM01 deployed on VMHost01 and stores the object in the $VM variable.

The second command gets all virtual disk drive objects on VM01 and stores the retrieved objects in $VirtDiskDrive. Using the '@' symbol and parentheses ensures that the command stores the results in an array in case the command returns a single object or a null value.

The last command returns the number of virtual disk drives associated with the virtual machine and then, if more than one exists, the command removes the second virtual disk drive (designated by the [1]) from the virtual machine.


PS C:\> $VM = Get-SCVirtualMachine | where { $_.VMHost.Name -eq "VMHost01.Contoso.com" -and $_.Name -eq "VM01" }PS C:\> $VirtDiskDrive = @(Get-SCVirtualDiskDrive -VM $VM)PS C:\> if($VirtDiskDrive.Count -gt 1){Remove-SCVirtualDiskDrive -VirtualDiskDrive $VirtDiskDrive[1]}

2: Remove all pass-through disks attached to a VM.

The first command gets the virtual machine object named VM02 and stores the object in the $VM variable.

The second command gets all virtual disk drive objects attached to VM02 that are not virtual hard disks (that is, only objects that represent pass-through disks are retrieved) and stores the pass-through disk objects in the $VDDs object array.

The last command uses an if statement to determine whether at least one pass-through virtual disk drive exists. If the result is one or more, the command then uses the foreach statement to remove each virtual disk drive from the object array. Using the Force parameter ensures the removal of each virtual disk drive from its virtual machine even if other VMM objects depend on that virtual disk drive.

NOTE: For more information about the standard Windows PowerShell foreach loop statement, type: "Get-Help about_ForEach".


PS C:\> $VM = Get-SCVirtualMachine | where {$_.Name -eq "VM02"}PS C:\> $VirtDiskDrives = @(Get-SCVirtualDiskDrive -VM $VM | where {$_.IsVHD -eq $False})PS C:\> if($VirtDiskDrives.Count -gt 0){foreach($VirtDiskDrive in $VirtDiskDrives){Remove-SCVirtualDiskDrive -Force -VirtualDiskDrive $VirtDiskDrive}}

3: Remove virtual disk drives attached to a VM by name.

The first command gets all virtual machine objects whose name match the string "WebSrvLOB" and stores the objects in the $VM object array.

The second command uses the ForEach cmdlet to iterate through the virtual machines stored in $VM to get all virtual disk drive objects from each virtual machine. The command stores the virtual disk drive objects in the $VirtDiskDrives object array. Then, the command uses a second ForEach loop to select all virtual disk drive objects whose name contains the string LOBData from the $VirtDiskDrives array and passes these objects to the Remove-SCVirtualDiskDrive cmdlet which removes the objects from VMM.


PS C:\> $VMs = @(Get-SCVirtualMachine | where {$_.Name -match "WebSrvLOB"})PS C:\> foreach ($VM in $VMs){$VirtDiskDrives = Get-SCVirtualDiskDrive -VM $VM; foreach ($VirtDiskDrive in $VirtDiskDrives){if($VirtDiskDrive.Name -match "LOBData"){Remove-SCVirtualDiskDrive -VirtualDiskDrive $VirtDiskDrive}}}

Related topics

 
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.