powershell - 从进程的命令行中提取参数
问题描述
我坚持捕获命令行值,我需要捕获命令行中的最后 4 个数字
屏幕截图来自 Process Explorer
我的代码如下
$process = "notepad.exe"
$CommandLine_QID = Get-WmiObject Win32_Process -Filter "name = '$process'" |
Select-Object CommandLine # just capture the command line
我需要从命令行拆分最后 4 位数字并从这里存储在一个变量中。
$Process_PID = Get-Process -Name "notepad" -ErrorAction SilentlyContinue | Select-Object ID
然后,我需要使用 $CommandLine_QID 的变量值对存储在数据库机器中的变量进行交叉检查
eg: db_var1 = 9998
if($CommandLine_QID -contain db_var1)
{
write-host "value contained."
}
解决方案
最简单的方法是使用 RegEx\d+$
从命令行中提取尾随数字:
$process = "notepad.exe"
$CommandLine_QID = [RegEx]::Match(
(Get-WmiObject Win32_Process -Filter "name = '$process'").CommandLine,'\d+$'
).Value
推荐阅读
- yii2 - Yii2 缩短 where () 和 orWhere ()
- python-3.x - place_forget() 的问题
- linux - Bash/ZSH 终端提示时间和日期
- javascript - React Links 跨页面传递变量
- mysql - SQL查询比较日期和时间mysql
- python - 使用破折号将小部件值导出到文件中
- c - 如何将二进制 0001,0010,0100,1000 转换为 0,1,2,3 以索引 4x4 二维数组?
- postgresql - 如何小写表中每一行的 JSONB 字符串数组的所有元素
- javascript - 下载 torrent 文件到谷歌驱动器或兆驱动器
- sql - 将行分组到范围内,同时也显示间隙