如何使用power shell命令获取hyper-v主机详细信息描述?

问题描述 投票:-2回答:1

如何使用power shell命令获取MS Hyper V中的主机和详细信息列表(即容量,CPU数量,内存)?

powershell hyper-v
1个回答
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

enter image description here

但这不是我们所能做的全部......

如果你想用这个做一个真实的报告,你可以使用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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.