powershell - I want to use get-counter ”\\$env:COMPUTERNAME\memory\% committed bytes in use” to append to a csv in the next line
问题描述
How can i append the get-counter into the cell in my csv without overwriting the current data.
$path = "v:\logg\logg.csv"
$ram = Get-Counter "\\$env:COMPUTERNAME\minne\% använda dedikerade byte"
$drivers = Get-Volume |Where-Object {$_.DriveLetter-ne $null}| select DriveLetter,Size,SizeRemaining,@{e={$_.Size - $_.SizeRemaining};l="Used"},@{e={[math]::Round(100 / ($_.size / $_.SizeRemaining) )};l="Total %"}
$drivers | Export-Csv $path -NoTypeInformation -Append -Force
Get-Date -Format "yyyy-MM-dd HH:mm"|Out-File $path -Append
I want it to look like this but with the get-counter added to the next empty cell:
If I try to add the $ram with add-content or out-file it will overwrite the whole file and remove the $drivers
If i try to do it like this:
$path = "v:\logg\hej.csv"
$ram = Get-Counter "\\$env:COMPUTERNAME\minne\% använda dedikerade byte"
$ram |Export-Csv $path -NoTypeInformation -Append -Force
$drivers = Get-Volume |Where-Object {$_.DriveLetter-ne $null}| select DriveLetter,Size,SizeRemaining,@{e={$_.Size - $_.SizeRemaining};l="Used"},@{e={[math]::Round(100 / ($_.size / $_.SizeRemaining) )};l="Total %"}
$drivers | Export-Csv $path -NoTypeInformation -Append -Force
It will look like this, overwriting the whole part of $drivers
解决方案
仅对于提交的字节%,您可以使用它...
$Counter = '\\{0}{1}' -f $env:COMPUTERNAME, '\Memory\% Committed Bytes in Use'
$RAM_CommBytesInUse_Pct = [int](get-counter -Counter $Counter).
CounterSamples[0].
CookedValue
刚才在我的系统上输出=39
但是,当您添加所有这些不具有相同列的东西时,您并没有制作 CSV 文件。例如,您插入的日期是DriveLetter
列中的字符串。要制作真正的 CSV 文件,您需要在新对象中重新排列属性。
推荐阅读
- .net - .Net HttpWebRequest ClientCertificates 未发送到 API
- npm - npm 将文件复制到共享驱动器
- sql - 如何从视图的连接和后续查询中索引视图?
- string - 如何使用 lex 来识别除引号之外的字符串?
- java - 无法使用 Mediarecorder 将录制的 Mp3 文件发送到服务器并且服务器接收失败
- c# - 'Environment.SpecialFolder.SystemX86' 在 32 位 Windows 操作系统上会返回什么?
- shell - 通过 curl 和进程响应的 Shell 脚本调用 API
- php - PHP 返回数字格式
- error-handling - WebSphere wsadmin testConnection 错误消息
- css - 我应该安装什么来让我的 Firebase 系统识别 class="btn btn-action hide" ?(我假设它是一个自定义构建的 CSS 类?)