Powershell 从进程中提取参数';命令行

Powershell 从进程中提取参数';命令行,powershell,tokenize,powershell-4.0,text-extraction,Powershell,Tokenize,Powershell 4.0,Text Extraction,我一直在捕获命令行值,我需要捕获命令行中的最后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 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  
然后,我需要使用存储在DB机器中的变量值$CommandLine_QID进行交叉检查

eg: db_var1 = 9998
if($CommandLine_QID -contain db_var1)
{
write-host "value contained."
}

最简单的方法是使用正则表达式
\d+$
从命令行中提取尾随数字:

$process = "notepad.exe"
$CommandLine_QID = [RegEx]::Match( 
    (Get-WmiObject Win32_Process -Filter "name = '$process'").CommandLine,'\d+$'
).Value

@Remko的可能重复:它不是重复的,因为链接问题的重点是获取一个进程的命令行,这是这个问题附带的(这个问题已经包含了该特定问题的解决方案)。这个问题的实质是:如何从包含空格分隔标记的字符串末尾提取4位数字?