Get-VM is doing nothing for Hyper-V

Michele picture Michele · Feb 7, 2014 · Viewed 18.9k times · Source

We have Windows 2008 R2 on our server. We are trying to write a PowerShell script to start/stop our VMs, but the get-vm command isn't working. There is no error message. The command is just not returning anything, but should be.

The code looks like this:

$temp = Get-VM -Server usa..... | where-object {$_.State -eq 'Running'}

We tried doing

$temp = Get-VM -name VM-VMNameAsSeenInHyperVMgr

and it doesn't return anything either.

We installed the update for PowerShell to get version 3 and that made the get-vm command work (not give error message), but it's still not returning any VMs.

I saw the forum post PowerShell "Get-VM" error.

But Hyper-V is installed now and shows up when I type at the PowerShell command line

Get-Module  -listavailable

At the start of my code I have

import-module Hyperv

There's also this:

[system.net.dns]::GetHostEntry(ip)

works and so does Get-Host.

We tried

Enable-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -All

but the command wasn't recognized as the name of a cmdlet.

I tried disabling UAC like this link , but it didn't work. This link shows commands I used: http://www.ehloworld.com/1026

When I typed

Set-UACStatus -Computer usa...net -Enabled [$false]

it gave the error message that Set-UACStatus wasn't recognized as the name of a cmdlet, etc. either. It didn't recognize Get-UACStatus either.

I'm not sure if there's another thing I need to import to use Get-VM. Or my co-worker was thinking maybe we're running into unknown AD issues. I think if it was Active Directory, it would be giving an error message about not having permission to do something, but it's not.

Answer

Michele picture Michele · Feb 7, 2014

I figured it out.

I needed to run PowerShell as administrator and then the Get-VM returned the list of VMs. I found the answer in forum post Get-VM doesn't work.