header image

Mass dismount VHDs

Posted by: | April 28, 2017 Comments Off on Mass dismount VHDs |

I’m going to be creating, using and discarding a number of VHDs for my diskpart and PowerShell series. When I have a number of them mounted I want a quick way to dismount them. Assuming I consistently keep them in the same folder then this very nicely does the job

Get-ChildItem -Path C:\test\ -Filter *.vhdx | Dismount-VHD

 

Why does it work?

Because Get-ChildItem emits System.IO.FileInfo objects that have a Path property and Dismount-VHD accepts pipeline input for the Path of the VHD to dismount:

-Path <String[]>
    Specifies one or more virtual hard disk files for which the corresponding virtual hard disks are to be dismounted.

    Required?                    true
    Position?                    1
    Default value                none
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false

under: PowerShell, Storage

Comments are closed.

Categories