Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

Powershell matching by two values

I try to get all Processes with starting letter w or s

Something like this:

Get-Process | Where-Object ProcessName -Match "^w.*" -or ProcessName -Match "^s.*" | Select-Object name, ID

but this doesnt work.

question from:https://stackoverflow.com/questions/65936218/powershell-matching-by-two-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since it's either one or the other, in the same position, you can use character class group ([characters]):

Get-Process | Where-Object ProcessName -match '^[ws]' | ...

The .* at the end of either pattern is moot.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...