【发布时间】:2018-12-15 19:42:58
【问题描述】:
我一直在捕获命令行值,我需要捕获命令行中的最后 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."
}
【问题讨论】:
-
@Remko:这不是重复的,因为链接的问题侧重于获取进程的命令行,这是这个问题的附带(已经包含解决方案特殊问题)。 this 问题的本质是:如何从包含空格分隔标记的字符串末尾提取一个 4 位数字?
标签: powershell tokenize powershell-4.0 text-extraction