Windows 如何从输出的第一行仅获取postgres.exe的PID

Windows 如何从输出的第一行仅获取postgres.exe的PID,windows,postgresql,powershell,cmd,command-prompt,Windows,Postgresql,Powershell,Cmd,Command Prompt,我正在使用这个命令- tasklist /FI "ImageName eq postgres.exe" 这是我得到的输出- Image Name PID Session Name Session# Mem Usage ========================= ======== ================ =========== ============ postgres.exe

我正在使用这个命令-

tasklist /FI "ImageName eq postgres.exe"
这是我得到的输出-

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
postgres.exe                  2300 Services                   0     19,752 K
postgres.exe                  2932 Services                   0      6,324 K
postgres.exe                  2992 Services                   0      8,660 K
postgres.exe                  3000 Services                   0      8,256 K
postgres.exe                  3008 Services                   0     11,128 K
postgres.exe                  3016 Services                   0      8,120 K
postgres.exe                  3024 Services                   0      7,756 K
postgres.exe                  3032 Services                   0      7,732 K
postgres.exe                  1684 Services                   0     20,732 K

回答评论和问题

(获取进程postgres)[0]。ID
Get进程
Get的所有正在运行的进程都名为postgres

[0]
抓取第一行


.ID
获取PID属性

如果要使用外部命令(如
postgret.exe
),您最好使用本机PowerShell命令来执行此操作。您可以告诉我如何使用PowerShell
(获取进程postgres)[0]执行此操作。ID