0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

プロセスのメモリ使用量

Last updated at Posted at 2024-12-22

プロセスごとのメモリ使用量を監視したかったので、以下スクリプトを作成しジョブ実行させることに
※Get-Process の引数にプロセス名指定するとプロセス単位で出力できる。

# 保存先ディレクトリのパスを指定
$directory = "C:\Logs"

# ディレクトリが存在しない場合は作成
if (-not (Test-Path -Path $directory)) {
    New-Item -ItemType Directory -Path $directory
}

# 現在の日付と時刻を取得してファイル名を作成
$fileName = Join-Path -Path $directory -ChildPath "$(Get-Date -Format 'yyyyMMdd').log"

# 現在の時刻を取得
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

# メモリ使用量を取得してログファイルに追記
Get-Process  | Select-Object @{Name="Timestamp";Expression={$timestamp}}, Name, @{Name="Memory (MB)";Expression={[math]::round($_.WorkingSet / 1MB, 2)}} | 
    Sort-Object "Memory (MB)" -Descending |
    Out-File -FilePath $fileName -Append

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?