1

I have started from scratch to be able to learn how to monitor our server (only one).

$dates=(get-date).ToString("s").Replace(":","-")

$page="page"+$dates+".csv"
get-wmiobject win32_pagefileusage | export-csv -path c:\tio\$page

$hyperpage="hyperpage"+$dates+".csv"
get-wmiobject win32_pagefileusage -computer Hyper | export-csv -path c:\tio\$hyperpage

$hyper="hyper"+$dates+".csv"
get-wmiobject win32_logicaldisk -computer Hyper | select-object -property DeviceID, FreeSpace, Size | Export-csv -path c:\tio\$hyper

$image="image"+$dates+".csv"
get-wmiobject win32_logicaldisk | select-object -property DeviceID, FreeSpace, Size | Export-csv -path c:\tio\$image

My aim is to find out how the free space on the hyper-v and the virtual host is growing.

Is it possible to merge them together as at this point it goes into 4 files. I would like to keep it low performance but merge as much as possible. Therefore the best thing would be an append function but don't want to upload the whole file in the memory every time unless I have to.

Many thanks in advance

TryHarder
  • 249
  • 1
  • 2
  • 13

1 Answers1

1

If I understand what you're asking, I think the simple solution is that export-csv includes an -Append option so you can keep appending to the files (although, since you create the filenames based on date/time down to the second, I'm not sure how much that would accomplish). If you wanted to keep it on a daily basis, for instance, you could try something like (I added -NoTypeInformation since type info in a csv generally annoys me unless you need it to rebuild an object, which in this case, we don't):

$dates=get-date -Format "yyyy-MM-dd"

$page="page$($dates).csv"
get-wmiobject win32_pagefileusage | export-csv -path c:\tio\$page -Append -NoTypeInformation

$hyperpage="hyperpage$($dates).csv"
get-wmiobject win32_pagefileusage -computer Hyper | export-csv -path c:\tio\$hyperpage -Append -NoTypeInformation

$hyper="hyper$($dates).csv"
get-wmiobject win32_logicaldisk -computer Hyper | select-object -property DeviceID, FreeSpace, Size | Export-csv -path c:\tio\$hyper -Append -NoTypeInformation

$image="image$($dates).csv"
get-wmiobject win32_logicaldisk | select-object -property DeviceID, FreeSpace, Size | Export-csv -path c:\tio\$image -Append -NoTypeInformation
Hunter Eidson
  • 493
  • 5
  • 8
  • Edison, thanks for your time. Yes I wanted to append it to a file/database continuously but because of the header I am not having success so I did the time base file version. – TryHarder Jul 03 '14 at 20:11