How to get list of hosts and details(viz. Capacity,CPU count,Memory) in MS Hyper V using power shell commands?
Asked
Active
Viewed 427 times
-2
-
Take a look at Microsoft's [documentation](https://learn.microsoft.com/en-us/powershell/module/hyper-v/?view=win10-ps). – vonPryz Apr 26 '19 at 12:54
-
Welcome to SO. You should start with taking the [Tour], continue to read [ask] and maybe [mcve] before you proceed. Did you try to search for it? I'm pretty sure that you're not the first human being with this requirement. ;-) – Olaf Apr 26 '19 at 13:09
1 Answers
0
If you launch PowerShell as an administrator you can use the Get-VM
command to get some pretty good info easily.
PS>Get-VMHost |
Select ComputerName,FullyQualifiedDomainName, MaximumStorageMigrations,`
LogicalProcessorCount, @{N='Memory(GB)';e={$_.MemoryCapacity / 1gb -as [int]}}
ComputerName FullyQualifiedDomainName MaximumStorageMigrations LogicalProcessorCount Memory(GB)
------------ ------------------------ ------------------------ --------------------- ----------
ELOPE WORKGROUP 2 16 64
If we like this view, we can export it as a CSV file and use this for auditing by just piping into Export-CSV
like so:
Get-VMHost | Select ComputerName,FullyQualifiedDomainName, MaximumStorageMigrations, LogicalProcessorCount, @{N='Memory(GB)';e={$_.MemoryCapacity / 1gb -as [int]}} |
export-csv c:\temp\vmhost.csv
But that's not all we can do...
If you wanted to make a real report out of this, you could instead use ConvertTo-HTML
with a little bit CSS for the basis of a real nice report.
$OSVer = Get-ciminstance win32_operatingsystem | select caption,Version
$pre=@"
<body id="css-zen-garden">
<div class="page-wrapper">
<style>
h1, h2, h3, h4, h5, h6 {
font-family: 'Corben', Georgia, Times, serif;
}
p, div, td {
font-family: 'Nobile', Helvetica, Arial, sans-serif;
}
h1 {
text-shadow: 1px 1px 1px #ccc;
}
h2 {box-shadow: 0 0 1em 1em #ccc;}
<br>
</style>
<h1>Hyper-V Report</h1>
<h2>$($env:ComputerName) - $($OSVer.Caption) [$($OSVer.Version)]</h2>
</header>
<div class="summary" id="zen-summary" role="article">
<p>A demonstration of what can be accomplished through a little bit of PowerShell and CSS</p>
</div>
</section>
</div>
"@
Get-VMHost | Select ComputerName,FullyQualifiedDomainName, MaximumStorageMigrations, LogicalProcessorCount, @{N='Memory(GB)';e={$_.MemoryCapacity / 1gb -as [int]}} |
ConvertTo-html -CssUri http://www.csszengarden.com/examples/style.css -PreContent $pre -PostContent "<i>Created automatically on $($Env:ComputerName) at $(get-date)" |
Out-file c:\temp\F.html -Force
start C:\temp\f.html

FoxDeploy
- 12,569
- 2
- 33
- 48
-
-
I have tried `Get-VMHost` but it does not contain detailed description of the host .Do you know how we can get more details out of this command? Like it's capacity,total number of CPUs and Memory. – Sumit Sawant Apr 26 '19 at 13:38
-
@SumitSawant PowerShell cmdlets show the first four or five properties of a cmdlet. To see all of them, you can use the pipe character like this with `Get-VMHost | Format-List`, this will show you all of the properties. If it doesn't work, ensure you have Hyper-V perms for your account. – FoxDeploy May 14 '20 at 13:09