有没有办法-Filter
使用 WMI 查询语言 (WQL) 指定 Get-WmiObject cmdlet的参数,以根据用于调用进程的“命令行”进行过滤?“命令行”是指 Windows 任务管理器的“进程”选项卡中显示的“命令行”。
我想获取一个进程 id 数组,其中命令行包含 string *Dev_SW*
。我不能使用名称,因为会有许多不等于*Dev_SW*
过滤器的同名进程在运行。
我希望将 XMLLINT 的输出放入 BASH 数组中。但我能得到的只是一个字符串。结果将返回许多命中,没有任何可以帮助解析返回字符串的模式。
//
,只有一个/
<?xml version="1.0" encoding="UTF-8"?>
<root>
<instance>
<absolutePath>/abc/def</absolutePath>
</instance>
<instance>
<absolutePath>/abc/hij</absolutePath>
</instance>
</root>
Run Code Online (Sandbox Code Playgroud)
#!/usr/bin/bash
declare -a wwArray=()
wwCount=$(xmllint --xpath 'count(//absolutePath)' "mcv.xml")
printf "wwCount: '%s' \n" ${wwCount}
i=1
while [ $i -le ${wwCount} ];
do
wwExtracted=$(xmllint --xpath '//absolutePath['${i}']/text ()' "mcv.xml")
printf " - absolutePath: '%s' \n" ${wwExtracted}
printf " - index: '%d' \n" ${i}
let i=i+1
done
Run Code Online (Sandbox Code Playgroud)
运行这个,输出是:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<instance>
<absolutePath>/abc/def</absolutePath>
</instance>
<instance>
<absolutePath>/abc/hij</absolutePath> …
Run Code Online (Sandbox Code Playgroud) 我有一个 powershell 脚本,可以关闭 MS Word 中打开的文件名与模式匹配的所有 MS Word 实例。有时会调用 Powershell 脚本,但没有运行 MS Word 实例。cmdlet Get-Process 用于查找 MS Word 并检查当前打开的文件的名称。
无论是 [NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand] 还是
[Microsoft.PowerShell.Commands.GetProcessCommand] 都被捕获。
{
$MSWordProcessHandle = Get-Process WINWORD
} catch [NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand] {
Write-Output "No instances of MS Word found running."
}
Run Code Online (Sandbox Code Playgroud)
我不断收到下面的错误。
Run Code Online (Sandbox Code Playgroud)Get-Process : Cannot find a process with the name "WINWORD". Verify the process name and call the cmdlet again. At C:\Utils\scripts\Dev_Set_Close.ps1:24 char:27 + $MSWordProcessHandle = Get-Process WINWORD + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (WINWORD:String) [Get-Process], ProcessCommandException + …
从arrayA
以下值开始。
arrayA=(‘valueA’ ‘valueB’ ‘valueC’)
*…Clever_One_line_Statement_goes_here…*
Run Code Online (Sandbox Code Playgroud)
在...Clever_One_line_Statement 之后,arrayA
有值....
arrayA=(‘’ ‘valueA’ ‘valueB’ ‘valueC’)
Run Code Online (Sandbox Code Playgroud)