Remove-SCVirtualDiskDrive

Remove-SCVirtualDiskDrive

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

構文

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

詳細説明

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.

パラメーター

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

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

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.

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-JobVariable<String>

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

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

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.

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

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.

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-PROTipID<Guid]>

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

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-RunAsynchronously

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

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-SkipDeleteVHD

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

エイリアス

none

必須?

false

位置は?

named

既定値

none

パイプライン入力を許可する

false

ワイルドカード文字を許可する

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.

エイリアス

none

必須?

true

位置は?

1

既定値

none

パイプライン入力を許可する

True (ByValue)

ワイルドカード文字を許可する

false

-Confirm

コマンドレットを実行する前に、ユーザーに確認を求めます。

必須?

false

位置は?

named

既定値

false

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

-WhatIf

コマンドレットを実行するとどのような結果になるかを表示します。コマンドレットは実行されません。

必須?

false

位置は?

named

既定値

false

パイプライン入力を許可する

false

ワイルドカード文字を許可する

false

<CommonParameters>

このコマンドレットは次の共通パラメーターをサポートします。-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer、-OutVariable.詳細については、以下を参照してください。 about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216)。

入力

入力型は、コマンドレットにパイプできるオブジェクトの型です。

出力

出力型は、コマンドレットによって生成されるオブジェクトの型です。

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

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