在 Powershell 中通过包含 WASP 的字符串选择进程名称

Selecting Processname by string containing with WASP in Powershell

我正在尝试 select 使用 WASP 的 Powershell 脚本中的某个进程名称。但是,问题是每次启动该进程时,它都会在扩展名之前给自己一个随机生成的字符串。

不过它总是包含扩展名“.tmp”。如果进程的末尾包含 .tmp,我是否可以 select 进程?在这种情况下,我尝试 select 的过程是 "is-RI4E5.tmp"。我需要 select 这个基于它包含末尾的扩展名,“.tmp”。

 ProcessName    ProcessId IsActive  Handle Title                                                            Class                                
-----------    --------- --------  ------ -----                                                            -----                                
powershell_ise      8652     True  133330 Administrator: Windows PowerShell ISE                            HwndWrapper[PowerShell_ISE.exe;;cf...
is-RI4E5.tmp        6720    False  461306 Setup                                                            TApplication                         
explorer            5472    False  264168 VNC Server                                                       CabinetWClass                        
explorer            5472    False  985230 vnc - Search Results in SharedFiles (\cas-fs1) (S:)             CabinetWClass                        
chrome              7636    False  329808 Central Arizona Supply - Home - Google Chrome                    Chrome_WidgetWin_1                   
cmd                 7592    False  264396 Administrator: C:\Windows\system32\cmd.exe                       ConsoleWindowClass                   
EXCEL               8860    False 1116322 Microsoft Excel - CAS Network IP Directory  [Compatibility Mode] XLMAIN                               
EXCEL               8860    False  395668 Printers                                                         MS-SDIb                              
VNCScan             9104    False  198140 Bozteck VENM Console 2013.6.3.230                                WindowsForms10.Window.8.app.0.378734a
EXCEL               8860    False  461030 CAS Network IP Directory  [Compatibility Mode]                   MS-SDIb         

我建议在启动 WASP 进程之前收集所有进程名称。启动后,再次收集所有进程并使用 Compare-Object 比较两个集合。当多个进程具有“.tmp”后缀时,这将减少误报的可能性。

$beforeWasp = Get-Process | Where-Object { $_.Name -Like '*.tmp' }

# start process here

$afterWasp = Get-Process | Where-Object { $_.Name -Like '*.tmp' }

Compare-Object -ReferenceObject $beforeWasp -DifferenceObject $afterWasp -PassThru