-- Checking if Hyper-V driver is configured to use a Virtual Switch code example
Example: -- Checking if Hyper-V driver is configured to use a Virtual Switch
Running powershell as Administrator fixed that problem for me. I was getting the same error.