Remove-SCVirtualDiskDrive

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> ] [-OnBehalfOfUser <System.String> ] [-OnBehalfOfUserRole <Microsoft.SystemCenter.VirtualMachineManager.UserRole> ] [-PROTipID <Guid]> ] [-RunAsynchronously] [-SkipDeleteVHD] [-Confirm] [-WhatIf] [ <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 Virtual Machine Manager (VMM) environment.

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

-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

-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

-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

-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 disk drive object, which can be retrieved by using the Get-SCVirtualDiskDrive cmdlet.

Examples

Example Example 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 then stores the object in the $VM variable.

The second command gets all virtual disk drive objects on VM01, and then 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 $Null.

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]}

Example 2: Remove all pass-through disks attached to a virtual machine

The first command gets the virtual machine object named VM02, and then 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, and then stores the pass-through disk objects in the $VirtDiskDrives object array. That is, the command retrieves only objects that represent pass-through disks.

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.

For more information about the standard Windows PowerShell Foreach statement, type Get-Help about_ForeEache.

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}}

Example 3: Remove virtual disk drives attached to a virtual machine by name

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

The second command uses Foreach 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 then 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}}}

Convert-SCVirtualDiskDrive

Get-SCVirtualDiskDrive

New-SCVirtualDiskDrive

Set-SCVirtualDiskDrive

Get-SCVirtualMachine