Library / Virtualization

VIRT-004 · Script

Virtual Disk Management

Reports virtual disk locations, sizes and provisioning type, and can expand an existing virtual disk or add a new one.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

Report mode (default) lists every virtual disk of the selected VMs: controller, file path, maximum size, space used on storage, and provisioning (Hyper-V dynamic, fixed or differencing; VMware thin, thick or eager zeroed thick). Nothing is changed.

-Action is planned in Report mode (the log says exactly what would happen) and carried out only in Apply mode: Expand grows one existing disk (-VMName and -DiskName, exactly one match) to -NewSizeGB. Shrinking is never done. The VM must have no checkpoints or snapshots, because disks with checkpoints cannot be resized safely. After expanding, extend the partition inside the guest (for example with Disk Management).

  • Add: creates a new empty disk of -NewSizeGB and attaches it to one VM. Hyper-V creates

a .vhdx (dynamic when -StorageFormat is Thin, fixed when Thick) on the SCSI controller; VMware adds a disk in -StorageFormat on -Datastore (or next to the VM).

Removing disks is intentionally not offered, because it can destroy data. Runs silently. No prompts.

Requirements

Windows PowerShell 5.1+. Hyper-V: the Hyper-V PowerShell module. VMware: VMware PowerCLI installed by you.

How to run it

  • Run from: an admin workstation or scheduled task with the Microsoft modules installed and app sign-in configured
  • This is an admin script for your Virtualization tenant, not a per-device endpoint script
  • User interaction: none with app-only sign-in
  • Schedule: run on demand, or weekly for reports

Settings

NameWhat it doesOptionsDefault
PlatformHyperV (default) or VMware.HyperV, VMwareHyperV
ModeReport (default) or Apply.Report, ApplyReport
ActionNone (default, report only), Expand or Add.None, Expand, AddNone
VMNameVirtual machine names, wildcards allowed, for example "FILESRV01". Empty = all VMs (report only). Expand and Add need exactly one VM.(none)
DiskNameExpand only. The disk to grow: Hyper-V file name or full path, for example "FILESRV01_Data.vhdx"; VMware disk name, for example "Hard disk 2".
NewSizeGBExpand: the new total size in GB (must be larger than now), for example 200. Add: the size of the new disk in GB, for example 100.0
StorageFormatAdd only. Thin (default; Hyper-V dynamic) or Thick (Hyper-V fixed size).Thin, ThickThin
DiskFolderHyper-V Add only. Folder on the host for the new .vhdx, for example D:\Hyper-V\Disks. Empty = the folder of the VM's first virtual disk.
DatastoreVMware Add only. Datastore name for the new disk, for example "DS-SSD-01". Empty = the VM's datastore.
ComputerNameHyper-V only. Name of a remote Hyper-V host, for example HV01. Leave empty to use this computer. The account running the script needs Hyper-V administrator rights on that host.
ServerVMware only. vCenter Server or ESXi host name, for example vcenter.school.local.
CredentialPathVMware only. Path to a credential file created with Get-Credential | Export-Clixml, for example C:\ProgramData\Runbookia\Secure\vcenter.xml. Create the file as the same account (for example SYSTEM) on the same computer that runs this script; Windows encrypts it so no other account can read it. Not needed with UseExistingSession.
UseExistingSessionVMware only. Reuse a vCenter Server or ESXi connection that is already open in this PowerShell session (from Connect-VIServer) instead of CredentialPath.False
IgnoreCertificateErrorsVMware only. Accept an untrusted or self-signed server certificate for this run only. Off by default; the PowerCLI setting on disk is not changed.False
ReportDirFolder for CSV reports. Default C:\ProgramData\Runbookia\Reports.C:\ProgramData\Runbookia\Reports

Exit codes

  • 0 = Report done, or the change was made
  • 1 = The requested change cannot be made (disk not found, would shrink, checkpoints present,
  • not exactly one VM), a named VM was not found, or the change failed
  • 2 = Script error (missing module, connection failed)

Testing steps

  1. Run it first with the mode set to Report on one test account or small group. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Report mode changes nothing. An expanded disk cannot be shrunk back by this script; restore from the backup taken before the change, or on Hyper-V shrink the guest partition first and then use Resize-VHD -ToMinimumSize. A disk added with Add can be detached and deleted in Hyper-V Manager or the vSphere Client once you confirm it holds no data.

Version and change log

VersionDateChanges
1.0.0November 2026First release.