How do I write the value of a single property of a object?

前端 未结 2 838
无人及你
无人及你 2020-11-22 10:08

This is how my current script looks like:

$cpu = Get-WmiObject win32_processor | select LoadPercentage
logwrite $cpu #this fuction writes $cpu into a .txt fi         


        
2条回答
  •  借酒劲吻你
    2020-11-22 10:44

    That is a pretty simple fix. Instead of selecting the LoadPercentage when running Get-WmiObject just select the property when calling your function. This will write only the number to your log file.

    $cpulogpath = "C:\Monitoring\$date.csv"
    function logwrite
    {
        param ([string]$logstring)
        add-content $cpulogpath -value $logstring
    }
    
    $cpu = Get-WmiObject win32_processor #don't select the property here
    logwrite $cpu.LoadPercentage #select it here
    

提交回复
热议问题