如何使用Power Shell命令在MS Hyper V中获取主机列表和详细信息(即容量,CPU数量,内存)?
答案 0 :(得分:0)
如果以管理员身份启动PowerShell,则可以使用Get-VM
命令轻松获得一些非常好的信息。
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
如果我们喜欢此视图,则可以将其导出为CSV文件,并通过如下方式将其用于Export-CSV
进行审核:
Get-VMHost | Select ComputerName,FullyQualifiedDomainName, MaximumStorageMigrations, LogicalProcessorCount, @{N='Memory(GB)';e={$_.MemoryCapacity / 1gb -as [int]}} |
export-csv c:\temp\vmhost.csv
但这不是我们所能做的...
如果您想以此做出真实的报告,则可以使用ConvertTo-HTML
和少量CSS来构成真实的报告。
$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