I am working on a script to capture key bits of server information from a large list of servers. With each server, I'd like to graph trending data from each server (drive usage, memory usage, etc.). With this I need a place to store the data after each run of the script, opting for storing the output into a CSV file (especially considering the ease of use of the Import/export csv functions in powerhsell).
My dilemna. Powershell's Export-csv does not have an append option. If you write to the file, it will always overwrite. Ugh. I could use the out-file cmd-let, but that requires defining the structure of my data to be output each and every time.
What I found was that I could do op_addition to a CSV file record if it contains 2 or more data records.
Name, IP
A, 192.168.1.1
B, 192.168.1.2
So, I've modified my script to put out 2 copies of the data, if the CSV does not exist; like below:
Now, I'll have to code around not using the first line of the CSV, but that sounds easier than coding the entire out-file cmdlet.
Comments
Post new comment