Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a wildcard in powershell parameter that doesn't natively support it?

Okay, sorry for the probably noobish question. I've been studying PowerShell for a while now, and have run into something I can't quite figure out how to word correctly for google.

In the most basic sense, here is what I'm trying to do.

Get-Process -id 76*

Now I understand that -id will not handle wildcard * characters. If I wanted to in theory use

Get-Process -id

and create a wildcard script for this purpose, how would I do this? Do i need to create my own function?

I'd like to add as well that PS says specifically the * is not a usable character for the -Name Parameter, yet I can use this. Is this an error with MS? Thank you for any advice in advance!

like image 770
cloudnyn3 Avatar asked Aug 26 '15 22:08

cloudnyn3


1 Answers

Use a (Where-Object) filter over the Get-Process output.

In this case:

Get-Process | where { $_.Id -like '76*' }

(where is an alias for Where-Object cmdlet.)

like image 128
user2864740 Avatar answered Sep 22 '22 01:09

user2864740