问题描述
我正在尝试获取有关Windows 10 PC上启动超过1天的进程的信息。我在Creationdate字段上没有成功匹配的内容。
wmic process where "Creationdate < $((Get-Date).AddDays(-1).ToShortDateString().toString())" get processid
wmic process where "Creationdate < 20200906012615" get processid
如果可能,我确实需要使用WMIC。
更新
我需要的完整查询的示例:
WMIC PROCESS WHERE "commandline LIKE '%_900\`"%' AND commandline LIKE '%data-dir%' AND Creationdate < 20200906012615" CALL TERMINATE
解决方法
这里是我的原始评论的一行powershell示例,已扩展为包含您提供的过滤条件:
$d=get-date -hour 0 -minute 0 -second 0;gcim win32_process -f "commandline like '%_900`"' and commandline like '%data-dir%' and creationdate<'$d'"|icim -m terminate
,
我会像这样在Powershell中进行操作,我认为这是最简单的方法。与get-wmiobject不同,Get-ciminstance实际上输出用于创建日期的日期时间对象。 wmic中的“ Process”是win32_process类的别名。
get-ciminstance win32_process |
where { $_.creationdate -lt (get-date).AddDays(-1) -and
$_.commandline -like '*svchost*' } |
remove-ciminstance -whatif
,
您必须将“.000000-300”附加到 CreationDate 过滤器。
就你而言:
WMIC PROCESS WHERE "commandline LIKE '%_900`"%' AND commandline LIKE '%data-dir%' AND Creationdate