Skip to content

Instantly share code, notes, and snippets.

@ytez
Last active April 12, 2021 05:41
Show Gist options
  • Save ytez/ede8d36b507064155e5a342128599c20 to your computer and use it in GitHub Desktop.
Save ytez/ede8d36b507064155e5a342128599c20 to your computer and use it in GitHub Desktop.
[Win7] ログオン時間をコマンドで調べる

概要

  • Windows 7 でログイン日時をコマンドで取得する
  • net user および WMIC を使用

環境

  • Windows 7 Enterprise 32bit
  • Active Directory ユーザ (非管理者)

参考

手順

net user コマンドで直近のログイン日時を調べる

net user <ユーザ名> /domain
この要求はドメイン <ADドメイン> のドメイン コントローラーで処理されます。

<省略>

最終ログオン日時                     2017/10/10 12:08:00

<省略>
コマンドは正常に終了しました。

WMIC (Windows Management Instrumentation Command line) を使用してイベントログから取得

> wmic ntevent where "(logfile='system' and timegenerated>='20171008' and eventcode='7001')" list /FORMAT:CSV

Node,EventIdentifier,EventType,Message,RecordNumber,SourceName,TimeGenerated
HostName,7001,3,カスタマー エクスペリエンス向上プログラムのユーザー ログオン通知,326484,Microsoft-Windows-Winlogon,20171010030759.913632-000
HostName,7001,3,カスタマー エクスペリエンス向上プログラムのユーザー ログオン通知,326060,Microsoft-Windows-Winlogon,20171010023649.393158-000
HostName,7001,3,カスタマー エクスペリエンス向上プログラムのユーザー ログオン通知,325366,Microsoft-Windows-Winlogon,20171009022158.783523-000
HostName,7001,3,カスタマー エクスペリエンス向上プログラムのユーザー ログオン通知,324768,Microsoft-Windows-Winlogon,20171008011515.824430-000

時刻はGMT表示のため注意。条件や出力形式の指定はヘルプを参照。

@ytez
Copy link
Author

ytez commented Apr 12, 2021

PowerShell + Win10 の場合下記でも取得できたが非常に時間がかかった

Get-WmiObject -Class Win32_NTLogEvent | 
Where-Object {
  $_.LogFile -eq 'System' `
  -and ($_.EventCode -eq 7001 -or $_.EventCode -eq 7002) `
  -and $_.TimeGenerated -ge 20210405
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment