In a PowerShell script running from a VM, I'd like to programmatically determine if the VM is a generation 1 Hyper-V VM, or if it is a generation 2 Hyper-V VM. Assume the VM is running a version of Windows compatible with running in a Gen 2 VM.

This question is not about detecting Hyper-V. Given that the script is running on a VM and the VM is running on Hyper-V, how do I determine the VM's generation number?

Possible leads:

[Sample C++ MSDN code to query VM Generation ID](https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-machine-generation-identifier?redirectedfrom=MSDN) - perhaps there is a way to convert this C++ code to C#, then dynamically compile it at runtime using Add-Type? I think this might be the best approach, but it's beyond my skill level.

[VMDE Project on GitHub](https://github.com/hfiref0x/VMDE) - has all kinds of methods for detecting VM platforms, but it's not written in PowerShell, and getting it to work is beyond my skill level

Thanks in advance!

Frank