Optimize-VHD

Optimize-VHD

Optimizes the allocation of space used by virtual hard disk files, except for fixed virtual hard disks.

Синтаксис

Parameter Set: Default
Optimize-VHD [-Path] <String[]> [-AsJob] [-CimSession <Microsoft.Management.Infrastructure.CimSession[]> ] [-ComputerName <String[]> ] [-Credential <System.Management.Automation.PSCredential[]> ] [-Mode <VhdCompactMode> {Full | Quick | Retrim | Pretrimmed | Prezeroed} ] [-Passthru] [-Confirm] [-WhatIf] [ <CommonParameters>]

Подробное описание

The Optimize-VHD cmdlet optimizes the allocation of space in or more virtual hard disk files, except for fixed virtual hard disks. The Compact operation is used to optimize the files. This operation reclaims unused blocks as well as rearranges the blocks to be more efficiently packed, which reduces the size of a virtual hard disk file.

To use Optimize-VHD, the virtual hard disk must not be attached or must be attached in read-only mode.

The compact operation can succeed without reducing the file size, if no optimization is possible.

Параметры

-AsJob

Runs the cmdlet as a background job.

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-CimSession<Microsoft.Management.Infrastructure.CimSession[]>

Запускает командлет в удаленном сеансе или на удаленном компьютере. Введите имя компьютера или объект сеанса, например выходные данные командлета New-CimSession или Get-CimSession. По умолчанию используется текущий сеанс на локальном компьютере.

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-ComputerName<String[]>

Specifies one or more Hyper-V hosts on which a virtual machine is to be optimized. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly.

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-Credential<System.Management.Automation.PSCredential[]>

Specifies one or more user accounts that have permission to perform this action. The default is the current user.

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-Mode<VhdCompactMode>

Specifies the mode in which the virtual hard disk is to be optimized. For a VHD disk, the default mode is Full. For a VHDX disk, the default mode is Quick. Valid modes are as follows:

--Full scans for zero blocks and reclaims unused blocks. (Allowable only if the virtual hard disk is mounted read-only.)

--Pretrimmed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The detection of unused space is less effective than Quick mode (in which the virtual hard disk had been mounted read-only) because the scan cannot query information about free space in the NTFS file system within the virtual hard disk. Useful when the VHDX-format file has been used by operating system instances that are at least Windows 8 or Windows Server 2012, or when this cmdlet has already been run on a .vhdx file in Retrim mode.

--Prezeroed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The unused space detection will be less effective than if the virtual hard disk had been mounted read-only as the scan will be unable to query information about free space in the NTFS file system within the virtual hard disk. Useful if a tool was run previously to zero all the free space on the virtual disk as this mode of compaction can then reclaim that space for subsequent block allocations. This form of compaction can also be useful in handling virtual hard disk containing file systems other than NTFS.

--Quick reclaims unused blocks, but does not scan for zero blocks. (Allowable only if the virtual hard disk is mounted read-only.)

--Retrim sends down retrims without scanning for zero blocks or reclaiming unused blocks. (Allowable only if the virtual hard disk is mounted read-only.)

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-Passthru

Specifies that an object is to be passed through to the pipeline representing the virtual hard disk to be optimized.

Псевдонимы

none

Обязательное поле?

false

Позиция?

named

Значение по умолчанию

none

Принимать входные данные конвейера?

false

Обрабатывать символы-шаблоны?

false

-Path<String[]>

Specifies one or more paths to the dynamic or differencing virtual hard disk files to be optimized.

Псевдонимы

FullName

Обязательное поле?

true

Позиция?

1

Значение по умолчанию

none

Принимать входные данные конвейера?

True (ByValue, ByPropertyName)

Обрабатывать символы-шаблоны?

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

Входы

Входной тип — это тип объектов, которые можно направить в командлет.

Выходные данные

Возвращаемый тип — это тип объектов, возвращаемых командлетом.

Примеры

Example 1

Runs the compact operation in Full mode. (If the VHDX-format file is not attached as read-only prior to the operation, it will default to Prezeroed mode.)

PS C:\> Optimize-VHD –Path c:\test\dynamic.vhdx –Mode Full

Example 2

Runs the compact operation in Retrim mode. (If the VHDX-format disk is not mounted as read-only prior to the operation, running the cmdlet returns an error.)

PS C:\> Optimize-VHD –Path c:\test\dynamic.vhdx –Mode Retrim

Example 3

Runs the compact operation in Quick mode. (If the VHDX-format file is not attached as read-only prior to the operation, it defaults to Pretrimmed mode.)

PS C:\> Optimize-VHD –Path c:\test\dynamic.vhdx –Mode Quick