Ben Armstrong made a post on how you should retrive a list of your virtual machines and their operation system. With this script as a base I started on making a Get-VmInfo function that should retrive a list of VM's with some usefull information. Hope you like it. :)
Update #1: I changed the script to run the query in jobs, making it faster to get information from multiple servers.
To use the function, type something like this: Get-VmInfo 192.168.17.23, 192.168.16.2 -Credential administrator | Out-GridView to get the result below

Or Get-VmInfo 192.168.17.23, 192.168.16.2 -Credential administrator | Format-Table to see it in PowerShell

The script is
function Get-VmInfo
{
<#
.SYNOPSIS
A PowerShell script to retrive Virtual Machines information from one or more Hyper-V servers
.DESCRIPTION
Retrives Virtual Machine information from Hyper-V servers
.EXAMPLE
Get-VmInfo 192.168.17.23, 192.168.16.2 -Credential administrator | Out-GridView
Retrives the virtual machines information from the two Hyper-V servers 192.168.17.23 and 192.168.16.2
.EXAMPLE
Get-VmInfo 192.168.17.23 | Out-GridView
Retrives the virtual machines information from the Hyper-V server 192.168.17.23 with default credentials
.Example
Get-VmInfo 192.168.17.23, 192.168.16.2 -Credential administrator | Group-Object OS | Format-Table -Property Name, Count
Name Count
---- -----
Windows Server 2008 R2 Datacenter 9
Windows 7 Ultimate 1
Windows Server (R) 2008 Datacenter 3
.NOTES
.LINK
http://mindre.net/post/Retrive-a-list-of-virtual-machines-in-Hyper-V-with-PowerShell.aspx
#>
Param
(
[parameter(Mandatory=$true)]
[String[]]
[ValidateNotNullOrEmpty()]
$HyperVServer,
[parameter(Mandatory=$false)]
[String]
[ValidateNotNullOrEmpty()]
$Credential
)
if ($HyperVServer -ne "." -and $Credential -ne "" -and $Credential -ne $null)
{
$wmiCredentials = Get-Credential $Credential
}
$jobs = @()
foreach ($hvServer in $HyperVServer)
{
$jobs += Start-Job -ArgumentList $hvServer, $wmiCredentials -ScriptBlock {
$hvServer = $args[0]
$wmiCredentials = $args[1]
$array = @()
if ($wmiCredentials -eq $null)
{
$VMs = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $hvServer
}
else
{
$VMs = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $hvServer -Credential $wmiCredentials
}
$infoArray = 0,1,4,100,101,103,105,106
$vmInfoArray = $VMs.GetSummaryInformation($null, $infoArray).SummaryInformation
foreach ($vmInfo in [array] $vmInfoArray)
{
switch ($vmInfo.EnabledState)
{
2 { $vmState = "Running" }
3 { $vmState = "Stopped" }
32768 { $vmState = "Paused" }
32769 { $vmState = "Suspended" }
32770 { $vmState = "Starting" }
32771 { $vmState = "Snapshoting" }
32773 { $vmState = "Saving" }
32774 { $vmState = "Stopping" }
32776 { $vmState = "Pausing" }
32777 { $vmState = "Resuming" }
default { $vmState = "Unknown" }
}
$out = new-object psobject
$out | add-member noteproperty Server $hvServer
$out | add-member noteproperty Name $vmInfo.ElementName
$out | add-member noteproperty State $vmState
if ($vmState -ne "Stopped")
{
$out | add-member noteproperty Memory "$($vmInfo.MemoryUsage) MB"
$out | add-member noteproperty Processors $vmInfo.NumberOfProcessors
$out | add-member noteproperty Load "$($vmInfo.ProcessorLoad) %"
$uptime = [int]($vmInfo.UpTime / 1000)
$out | add-member noteproperty UpTime "$([Math]::Floor($uptime / 86400)) days, $([Math]::Floor($uptime / 3600 % 24)) hours, $([Math]::Floor($uptime / 60 % 60)) minutes"
$out | add-member noteproperty OS $vmInfo.GuestOperatingSystem
}
$out | add-member noteproperty Guid $vmInfo.Name
$array += $out
}
write-output $array
}
}
$array = @()
foreach ($job in Wait-Job -Job $jobs)
{
$array += Receive-Job $job
}
Remove-Job -Job $jobs
write-output $($array | Select-Object Server, Name, State, Memory, Processors, Load, UpTime, OS, Guid | Sort-Object Server, Name)
}
PowerShell is quickly becoming the main framework for scripting stuff in the Windows world. By default PowerShell 2.0 is enabled on both Windows 7 and Windows Server 2008 R2.
The PowerShell profile
PowerShell has a profile feature that is a .ps1 script that loads when you open PowerShell. This script is neat for storing custom functions that come in handy. The script is not there by default so you have to create it yourself.
You can check if you already have a profile by typing Test-Path $profile
To create a profile type New-Item -path $profile -type file -force and notepad $profile to edit it.
You need to set executionpolicy to allow scripts or you will get an error.
Run PowerShell as Administrator and type Set-ExecutionPolicy RemoteSigned, this allows for local scripts to be exectuted in PowerShell
Sample script - A PowerShell version of wget
Now that we have our profile what is better to put in it than a Get-File function.
This simple script take one or more url's and download them into the destination path. The last command in the script adds the alias wget to Get-File so that you can also type wget
To use it simply type something like Get-File -Url "http://mindre.net/Hyper-V_Monitor.gadget" -DestinationPath "C:\Users\Tore\Desktop"
Put this in your $profile file:
function Get-File
{
<#
.SYNOPSIS
A simple PowerShell script to retrive files
.DESCRIPTION
Retrives one or more files to a directory
.EXAMPLE
Get-File -Url "http://mindre.net/Hyper-V_Monitor.gadget" -DestinationPath "C:\Users\Tore\Desktop"
Retrives the file "Hyper-V_Monitor.gadget" to the folder "C:\Users\Tore\Desktop"
.NOTES
The script assumes that you'r not behind a web proxy and that the url's end with a filename like "http://my.site.com/logo.jpg".
If the destination path does not exist the script will create it.
.LINK
http://mindre.net/post/PowerShell-profile-and-a-sample-script.aspx
#>
Param
(
[parameter(Mandatory=$true)]
[String[]]
[ValidateNotNullOrEmpty()]
$Url,
[parameter(Mandatory=$true)]
[String]
[ValidateNotNullOrEmpty()]
$DestinationPath
)
$wClient = New-Object System.Net.WebClient
[System.Net.GlobalProxySelection]::Select = [System.Net.GlobalProxySelection]::GetEmptyWebProxy()
$tp = Test-Path $DestinationPath
if ($tp -eq $false) { New-Item $DestinationPath -ItemType directory -Force | Out-Null }
$Url | % {
$regex = [Regex]::Split($_, "/")
$file = Join-Path $DestinationPath $regex[$regex.Length - 1]
Write-Host $file -NoNewline
$wClient.DownloadFile($_, $file)
Write-Host " 100%"
}
}
New-Item -Path alias:wget -Value Get-File | Out-Null

I've created a sidebar gadget so I can see what the Hyper-V server is doing from my workstation.
The gadget can list multiple servers at once and also support vmconnect when double clicking on a VM.
PS: The gadget uses WMI to connect to the server so the user might need to follow John Howard's guide remote WMI access on both the client and the Hyper-V server.
Version 5.2 is out!
The latest version of my gadget has been tested and is now ready to be released! After a rewrite of the gadget, it is now better, faster and more awesome than ever before! :)
The gadget is now packed with more features than ever while still keeping the UI simple, alot of neat little features. ;)
Some of the new features are:
- VM CPU graph
- Wake on Lan support
- VM RDP (If the host is running 2008 R2)
- Multilanguage support.
5.2 (07.03.2010)
- Optimized performance releated to VM-RDP addresses.
- Added ability to only display a number of VM at the time. (Good for people having more VM than fits on the screen)
- If a VM not in the screen is off the host's name will be red, if it's paused or starting it will be orange.
- Added ability to minimize a server in the monitor view. Holding mouse cursor over the Host will display information about the VM's
- Added option to choose what type of RDP setting to the host on a pr. host basis.
- Added VM information when holding the mouse cursor over a VM (The gadget needs focus for this to work..)
- Added Orange background to a VM that is running with the Health-status not beeing OK. (Happens when a VM is booting up by bluescreen)
- Added Pause button to the VM controls.
- Wibout Bootsma is now part of the gadget development. :)
More...
Posted by
Tore Lervik on
9/14/2009 2:52 PM |
Comments (0)
Last week I started playing around with a new theme for my website. The old one was alright, but I wanted something that looked a bit more polished and with some key HCI (Human Computer Interaction) elements.
The old theme MindreNetv2 had three key problems:
- It didn't seperate posts well, making it hard to get a quick overview of the articles.
- The sidebar on the right left side had the same color and could clutter the articles with unintresting information.
- The topbar with buttons was taking space, and attraction with it's distinct color, that it didn't need.
I wanted something that seperated the articles well and with a professional look. The start was a light background for the article div's, and a dark background for the main page to make the seperations more distinct. This also helped seperating the sidebar from the articles. Then I started removing most of the links used on the site to provide a cleaner (Less is more) look. Since the websites two functions are articles and the articles comments, most of the links were easy to remove.
The result
- A more professional\polished look with the use of PNG and transperancy.
- Less clutter to distract the user away from the articles content.
- A more distinct article-area that also is the most visible area on the website.
- No menybar at the top. (Clicking the Logo brings you back to the main page)
I feel the new theme looks good, and I hope you find it easy to use. :)
One of my first posts here on my blog was about the two PowerShell scripts that I made for taking snapshots and backup of Virtual Machines. It was a simple script, but alot of people seemed to like them. Time has passed, and iv'e changed how I want to perform my backups.
How to configure Windows Server Backup
-
Install the Windows Server Backup feature with Server Manager, and make sure you include the command-line tools available.
-
Add this string to the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WindowsServerBackup\Application Support\{66841CD4-6DED-4F4B-8F17-FD23F8DDC3DE}\Application Identifier\Hyper-V
Link: http://support.microsoft.com/kb/958662
-
Restart the server
-
Start Windows Server Backup and create a new schedule.
Select C: and the volume you have your VM's on. (Do not select .vhd files directly, apparently VSS doesn't like that)
Select a dedicated backup location. (The backup will fail under schedule if you select a normal volume)
-
Try to run the backup once, it should run without fail. :)
(Bonus) Monitor your backup in case of an error
A backup is no good if you don't get notified if there was an error. It's a classic when companies find out that their backup solution stopped working 6 months ago, just when they needed the backup.
I've created a new simple PowerShell script that checks the last successfull backup. The script will send an email if the last successfull backup is older than a given amount of hours.
Configuration is in the start of the script. By default the script will check if last backup is older than 24 hours, and it will also send a "backup succeded" mail.
BackupCheck.ps1 (1.04 kb)
To configure a schedule for the script to run, start Task Scheduler and create a new task.
Under Action, click Add and enter Powershell as program and "& 'C:\Hyper-V\BackupCheck.ps1'" as argument.
Under Triggers, click Add and enter your desired intervall. I've set mine to run 2 hours after the backup schedule.
With this you should be able to have a pretty good overview over your backup :)
Posted by
Tore Lervik on
8/30/2009 4:20 PM |
Comments (0)
Website problems
In the start of July I noticed the server hosting my blog was turned off. After a quick look I noticed that I had forgot about the expire date of Windows Server 2008 R2 Beta 1. This was 1 day before I went away on holiday, and 2008 R2 was also rumored to go RTM soon. I decided to wait with the server, and configure it with the RTM build once it was available. Since 2008 R2 RTM is out, my server is once again online! :)
New studies
I've been studying Computer Science at Oslo University College for the last 3 years. This summer we delivered our bachelor project (which we got an A!) and I finished my bachelor degree in Computer Science.
After a short summer I'm now once again back in school. I've started studying for a Master degree in Information Security at Gjøvik University College, and should hopefully be done with my degree in the summer of 2011.
There are two trends in the IT world that until now has been incompatible with each other.
- Multiple monitors to get a better overview.
- Work on a VM over RDP to enable easier access and “sandbox” the work environment.
With Windows 7 (7057) the latest RDP changes are in, and the result is pretty impressive. After creating a new Windows 7 VM in Hyper-V I connected using RDP on my client.

Note the “Use all my monitors for the remote session” checkbox under Display.
The VM comes up on both monitors and acts just like my local client does. Finally I can run my workstation virtualized without losing dual screen support.
Note: Windows 7 is required on both clients.
The new taskbar in Windows 7 Beta 1 has changed quite a bit since the familiar Vista and XP taskbar that we are used to.
There are a number of new features and changes that I find very useful with the new taskbar. Here are some of my experiences with the new taskbar so far.
More...
Windows 7 seems to be quickly shaping up with its new taskbar and a much more polished UI than Vista.
After testing it on both my laptop and in Hyper-V I've found some interesting stuff I wanted to share.
More...
Your system administrator does no allow the use of saved credentials
to log on to the remote computer <computername> because its identity
is not fully verified. Please enter new credentials.
If you are using Hyper-V and your client is in a domain you might have seen this dialog a couple of times.
Or if your testing out VMM 2008 Beta in a domain environment you must have gone nuts by now.
The workaround for it is pretty simple.
On your domain server, open up Group Policy Management Editor and go to Computer Configuration -> Administrative Templates -> System -> Credentials Deligation.
Double click on Allow saved credentials with NTLM-only Server Authentication, click Show and add "*servername.domain" to the list.
My server is named Exia and my domain is home.mindre.net, so I added *EXIA.home.mindre.net to the list.
Now go on your client and open a Comand Prompt with admin rights and run gpupdate.
Cached Credentials in a domain environment should now work :)