如何使用 power shell 命令获取 hyper-v 主机的详细描述?
How to get hyper-v host detail description using power shell command?
如何使用 power shell 命令在 MS Hyper V 中获取主机列表和详细信息(即容量、CPU 计数、内存)?
如果您以管理员身份启动 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
如何使用 power shell 命令在 MS Hyper V 中获取主机列表和详细信息(即容量、CPU 计数、内存)?
如果您以管理员身份启动 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