Scripts pour savoir les systèmes d’exploitations des machines virtuelles Hyper-V
Ben Armstrong, Virtualization Program Manager, explique sur son blogue les deux scripts qu’il crée pour apprendre quelles systèmes d’exploitation roulent sur les machines virtuelles du serveur Hyper- V :http://blogs.msdn.com/virtual_pc_guy/archive/2010/04/14/scripts-to-inventory-virtual-machines-hyper-v.aspx
Exemple :
# Prompt for the Hyper-V Server to use
$HyperVServer = Read-Host"Specify the Hyper-V Server to use (enter '.' for the local computer)"
# Get all virtual machine objects on the server in question
$VMs = gwmi -namespace root\virtualization Msvm_ComputerSystem -computername $HyperVServer -filter"Caption = 'Virtual Machine'"
# Create an empty hashtable
$table = @{}
# Go over each of the virtual machines
foreach ($VMin [array] $VMs)
{
# Get the KVP Object
$query ="Associators of {$VM} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
$Kvp = gwmi -namespace root\virtualization -query $query -computername $HyperVServer
# Get the OSName value out of the guest KVP data
$xml = [xml]($Kvp.GuestIntrinsicExchangeItems | ? {$_-match"OSName"})
$entry = $xml.Instance.Property | ?{$_.Name-eq"Data"}
# Filter out offline virtual machines and virtual machines which did not return KVP data
if ($entry.Value)
{$value = $entry.Value}
elseif ($VM.EnabledState-ne 2)
{$value ="Offline"}
else {$value ="Unknown"}
# Count up the values and store it in a hashtable
if ($table.ContainsKey($value))
{$table[$value] = $table[$value] + 1 }
else
{$table[$value] = 1}
}
# Display the results in a nicely formated and sorted manner
$table.GetEnumerator() | Sort-Object Name | Format-Table -Autosize
Roxana Panait, MSFT ________ Votez l’article qui vous est utile ou postez un pour participer au concours : Appel a la contribution! Publiez un tip ou un petit tutorial (comment faire) sur la technologie que vous connaissez le mieux ! - http://social.technet.microsoft.com/Forums/fr-FR/1635/thread/c0fc6847-a4b0-4253-85e9-8eac0cc95aa0