Skip to content

select items from a list that match a certain expressionin powershell

2011/07/03

To pick items from a list that match an expression or comparison, you can use compare operators on the list. Also using regular expressions and the match operator picks items from a list.

The first example picks all list entries that are alphabetically smaller than “k”. The second example picks al entries that start with the letter h

PS C:\Dok> $names = "hans","bert","peter","harry","james","mike","sly"
PS C:\Dok> $names -lt "k"
hans
bert
harry
james
PS C:\Dok> $names -match "^h"
hans
harry
Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: