get-wmiobject sql join in powershell - 尝试查找远程系统的物理内存与虚拟内存

发布于 2024-09-01 04:32:24 字数 471 浏览 1 评论 0原文

get-wmiobject -query "Select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

get-wmiobject -query "Select TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

我正在尝试使用以下命令完成此脚本这样的输出:

Computer        Physical Memory      Virtual Memory
server1         4096mb               8000mb
server2         2048mb               4000mb

get-wmiobject -query "Select TotalPhysicalMemory from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

get-wmiobject -query "Select TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer COMPUTERNAME >>output.csv

I am trying to complete this script with an output as such:

Computer        Physical Memory      Virtual Memory
server1         4096mb               8000mb
server2         2048mb               4000mb

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-09-08 04:32:24

有什么事情阻止你做这样的事情吗?

gwmi -query "Select TotalPhysicalMemory,TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer $COMPUTERNAME |
  select @{Name='Computer', Expression=$COMPUTERNAME},
         @{Name='Physical Memory', Expression=$_.TotalPhysicalMemory},
         @{Name='Virtual Memory', Expression=$_.TotalPageFileSize} |
  Export-Csv

(未经测试,因为 Get-WmiOject 不知道此处的 Win32_LogicalMemoryConfiguration 类。但可能有效。)

Is anything keeping you from doing something like this?

gwmi -query "Select TotalPhysicalMemory,TotalPageFileSpace from Win32_LogicalMemoryConfiguration" -computer $COMPUTERNAME |
  select @{Name='Computer', Expression=$COMPUTERNAME},
         @{Name='Physical Memory', Expression=$_.TotalPhysicalMemory},
         @{Name='Virtual Memory', Expression=$_.TotalPageFileSize} |
  Export-Csv

(Untested, since Get-WmiOject doesn't know the class Win32_LogicalMemoryConfiguration here. But might work.)

梦亿 2024-09-08 04:32:24

Win32_LogicalMemoryConfiguration 似乎已过时。我认为这个函数会得到你想要的信息:

function Get-MemoryInfo
{
    Process
    {
        Get-WmiObject Win32_OperatingSystem -ComputerName $_ |
        % {
            New-Object PSObject |
            Add-Member NoteProperty Computer $_.CSName -PassThru |
            Add-Member NoteProperty VirtualMemoryMB ([int]($_.TotalVirtualMemorySize / 1KB)) -PassThru
        } |
        % {
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Computer
            $_ | Add-Member NoteProperty PhysicalMemoryMB ([int]($cs.TotalPhysicalMemory / 1MB)) -PassThru
        }
    }
}

你可以通过管道将计算机列表输入Get-MemoryInfo。如果您想要 csv 文件,则将输出通过管道传输到 Export-Csv 中。

Win32_LogicalMemoryConfiguration appears to be obsolete. I think this function will get the information you want:

function Get-MemoryInfo
{
    Process
    {
        Get-WmiObject Win32_OperatingSystem -ComputerName $_ |
        % {
            New-Object PSObject |
            Add-Member NoteProperty Computer $_.CSName -PassThru |
            Add-Member NoteProperty VirtualMemoryMB ([int]($_.TotalVirtualMemorySize / 1KB)) -PassThru
        } |
        % {
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $_.Computer
            $_ | Add-Member NoteProperty PhysicalMemoryMB ([int]($cs.TotalPhysicalMemory / 1MB)) -PassThru
        }
    }
}

You can pipe the list of computers into Get-MemoryInfo. Then pipe the output into Export-Csv if you want a csv file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文