Get -WmiObject SQL انضم إلى PowerShell - في محاولة للعثور على الذاكرة الفعلية مقابل الذاكرة الافتراضية للأنظمة البعيدة

StackOverflow https://stackoverflow.com/questions/2816124

  •  26-09-2019
  •  | 
  •  

سؤال

get -wmiObject -Query "Select TotalPhysicalMemory من Win32_LogicalMemoryConfiguration" -Computer Computername >> output.csv

get -wmiObject -Query "Select TotalPageFilespace من Win32_LogicalMemoryConfiguration" -computerame computername >> output.csv

أحاول إكمال هذا البرنامج النصي مع إخراج على هذا النحو:

Computer        Physical Memory      Virtual Memory
server1         4096mb               8000mb
server2         2048mb               4000mb
هل كانت مفيدة؟

المحلول

هل يمنعك أي شيء من فعل شيء كهذا؟

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 هنا. ولكن قد تعمل.)

نصائح أخرى

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. ثم قم بتنشيط الإخراج في Export-CSV إذا كنت تريد ملف CSV.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top