VMware Cloud Community
BrianGordon84
Contributor
Contributor

PageFile Info To Excel - Script Modification

This is the script I use right now to kick out the size of the pagefile and the drive it's on. It writes this info directly to the console. I've got to run this against 900+ vm's so I need it to output to an excel sheet. Any help would be appreciated.

gc 'd:\Powershell Scripts\servers.txt' | % {
    $server = $_

   $pagefile = gwmi -computer $server Win32_PageFile
  
     foreach($pgf in $pagefile){
      $sz += $pgf.FileSize}
$fm = $sz/1GB
Write-Host $fm
Write-Host $pagefile.Drive

}

I need the following colums: VM Name | Pagefile Drive Letter | Pagefile Size.

Some vm's have a pagefile on c:\ AND another one on another drive. I need to account for that in the script so it doesn't screw up the formatting.

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Does this work for you ?

$report = gc 'd:\Powershell Scripts\servers.txt' | % {
    $server = $_
    $pagefile = gwmi -computer $server Win32_PageFile      foreach($pgf in $pagefile){         New-Object PSObject -Property @{             "VM Name" = $server
            "Page File Drive letter" = $pgf.Drive             "Pagefile Size" = $pgf.FileSize/1GB         }     } } $report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos