Good day.

There is a hypervisor with a bundle of virtual machines. VHDs are stored decentralized, some are encrypted. In the case of a forced reboot of the machine to which the encrypted disks are connected, they fall off.

Is it possible to issue a type check in one script: if VHD is not available → disconnect from the machine? And if so, is it possible to somehow collect the VHD locations for verification in one single request in order not to make such a check on each disk manually?

    1 answer 1

    One, as it turned out, is impossible. Ideal with encrypted drives: check for presence of a file and disconnect it from the machine if it is missing. For normal tests return true, even if the virtual machine is stopped.

    For each machine we have this script:

    if (-NOT (test-path путь:\до\файла.vhdx)) {Remove-VMHardDiskDrive -VMName *ИмяМашины* -ControllerType *ТипКонтроллера* -ControllerNumber *Номер* -ControllerLocation *Номер*} 

    Then the scripts can be collected in one batch file and sent to startup. If someone has a more elegant method, please comment.