Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Formatting CSV Output

$
0
0

Hey guys I’m wrapping up a tool to run some resource checks for our Server Monitoring group and here’s what I have as v0.1:

$memT = 85 $cpuT = 85 While($true){ $mem = Get-WmiObject win32_operatingsystem | Foreach {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize)} $cpu = (Get-WmiObject win32_PerfFormattedData_PerfOS_Processor -filter "Name='_Total'").PercentProcessorTime if ($mem -ge $memT -or $cpu -ge $cpuT){ $Day = Get-Date $Log = New-Object PSObject -Property @{ FirstColumn = $Day; SecondColumn = "$mem%"; ThirdColumn = "$cpu%" } Export-CSV -InputObject $Log -Path C:ResourceCheck.txt -NoTypeInformation -Append Start-Sleep -m 10 } elseif ($mem -lt $memT -or $cpu -lt $cpuT){ Start-Sleep -m 1 } } 

Really the only thing I’m looking to modify if possible is the .txt output. If instead of it literally being called FirstColum, SecondColumn, etc I could label them CPU, RAM, Date and make sure they actually output in the order that would be sensible that’d be great. Currently they’re spitting out as Second, Third, First and the associated data which is honestly okay I suppose but I’m not sure if that output will be consistent in that order. I’m sure this is super simple, but thank you in advance for any assistance!

submitted by /u/TheGuutz
[link] [comments]

The post Formatting CSV Output appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles