【问题标题】:I'm having trouble getting the Get-Counter part of the script to output in the CSV file我无法将脚本的 Get-Counter 部分输出到 CSV 文件中
【发布时间】:2019-05-09 00:47:54
【问题描述】:

当我尝试输入以下脚本时,我希望在 CSV 中提交内存,但我只得到 Get-Volume 部分。

这是我的代码:

function Get-tid {
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}

Write-Output "$(Get-tid) Informationen från sökningen $dc" |
    Out-File C:\logg\logg.csv -Append

Get-Volume |
    select DriveLetter, Size, SizeRemaining,
        @{e={$_.Size - $_.SizeRemaining};l="Använt"},
        @{e={[Math]::Round(100 / ($_.Size / $_.SizeRemaining) )};l="Antal %"} |
    Add-Content -Path C:\logg\logg.csv 

Get-Counter ”\\$env:COMPUTERNAME\memory\% committed bytes in use” |
    Export-Csv -Append -Path C:\logg\logg.csv -Force

【问题讨论】:

  • Get-Counter 以当前语言环境返回项目。也许只需在 ISE 中运行 Get-Counter 即可在您的语言环境中找到准确的措辞。例如:在我的荷兰机器上,它被称为 "\geheugen\percentage toegewezen bytes in gebruik"

标签: powershell csv output


【解决方案1】:

也使用 Out-File 而不是 Export-CSV:

Get-Counter ”\\$env:COMPUTERNAME\memory\% committed bytes in use” | Out-file "C:\logg\logg.csv -Append -Force

【讨论】:

    猜你喜欢
    • 2019-01-08
    • 1970-01-01
    • 2013-04-01
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多