Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-VM is doing nothing for Hyper-V

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.

like image 513
Michele Avatar asked Feb 07 '14 13:02

Michele


People also ask

How do I run a VM on Hyper-V?

Enable the Hyper-V role through Settings Right click on the Windows button and select 'Apps and Features'. Select Programs and Features on the right under related settings. Select Turn Windows Features on or off. Select Hyper-V and click OK.

How do I enable Hyper-V Commandlets in PowerShell?

To use Server Manager to enable Hyper-V's PowerShell module, open the Add Roles and Features wizard and proceed through to the Features page. Navigate to Remote Server Administration Tools -> Role Administration Tools -> Hyper-V Management Tools and check Hyper-V Module for Windows PowerShell.

How do I restart the Hyper-V virtual machine management service?

To restart VMMS using the Service Manager: 1.In theHyper-V Manager click the server on which you want to stop the service, then clickAction, then click Stop Service. 2. ClickAction, then click Start Service.


1 Answers

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.

like image 156
Michele Avatar answered Oct 20 '22 00:10

Michele