Remove-SCVirtualHardDisk
Removes a virtual hard disk object from a virtual machine or template, or from the VMM library.
Syntax
Default (Default)
Remove-SCVirtualHardDisk
[-VirtualHardDisk] <VirtualHardDisk>
[-JobGroup <Guid>]
[-Force]
[-RunAsynchronously]
[-PROTipID <Guid>]
[-JobVariable <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Remove-SCVirtualHardDisk cmdlet removes a virtual hard disk object from a virtual machine or template, or from the Virtual Machine Manager (VMM) library. Remove-VirtualHardDisk also deletes the corresponding virtual hard disk file (a Windows-based .vhd file, a Citrix XenServer-based .vhd file, or a VMware-based .vmdk file) from the library server.
If the virtual hard disk is attached to a virtual disk drive on a virtual machine or template (and if you do not use the Force parameter), VMM lists the container that contains the virtual hard disk and prompts you to confirm that you want to remove the virtual hard disk:
If you reply Yes, VMM removes the association between the virtual hard disk and the container to which it is attached, and then deletes the virtual hard disk object from VMM.
If you reply No, the operation is cancelled.
This cmdlet returns the object upon success (with the property MarkedForDeletion set to True) or returns an error message upon failure.
Examples
Example 1: Remove a virtual hard disk object from the library
PS C:\> $VHD = Get-SCVirtualHardDisk -VMMServer "VMMServer01.Contoso.com" | where { $_.Name -eq "VHD01.vhd" -and $_.LibraryServer.Name -eq "LibraryServer01.Contoso.com" }
PS C:\> Remove-SCVirtualHardDisk -VirtualHardDisk $VHD
The first command gets the virtual hard disk object named VHD01.vhd stored on LibraryServer01 and stores the returned object in the $VHD variable.
The second command removes the virtual hard disk object stored in $VHD from the library and deletes the corresponding file from the file system on the library server.
Example 2: Remove a virtual hard disk from a virtual machine
PS C:\> Get-SCVMMServer -ComputerName "VMMServer01.Contoso.com"
PS C:\> $VHD = Get-SCVirtualMachine -Name "VM01" | Get-SCVirtualHardDisk | where { $_.Name -match "DataDisk" }
PS C:\> $VHD | Remove-SCVirtualHardDisk
The first command connects to VMMServer01.
The second command gets the virtual machine object named VM01, gets all virtual hard disks on VM01 whose name includes the string "DataDisk", and then stores these virtual hard disk objects in an array named $VHD.
The third command removes each virtual hard disk object stored in the $VHD array from the virtual machine and deletes each corresponding file from the file system on the library server.
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
Forces the command to run without asking for user confirmation.
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 |
-JobGroup
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.
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 |
-JobVariable
Specifies that job progress is tracked and stored in the variable named by this parameter.
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 |
-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 |
-VirtualHardDisk
Specifies a virtual hard disk object.
Parameter properties
Type: | VirtualHardDisk |
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
- Requires a VMM virtual hard disk object, which can be retrieved by using the Get-SCVirtualHardDisk cmdlet.