PoshCode Archive  Hex Artifact Content

Artifact 29bd6051b440c0118856743605002910f3b24bd7a7eb28c139ba4e012159e7f0:

  • File Where-like.ps1 — part of check-in [02558a9c7e] at 2018-06-10 13:39:01 on branch trunk — Where-like function works as a pipeline console filter. (user: sibroller size: 564)

0000: 23 20 65 6e 63 6f 64 69 6e 67 3a 20 61 73 63 69  # encoding: asci
0010: 69 0d 0a 23 20 61 70 69 3a 20 70 6f 77 65 72 73  i..# api: powers
0020: 68 65 6c 6c 0d 0a 23 20 74 69 74 6c 65 3a 20 57  hell..# title: W
0030: 68 65 72 65 2d 6c 69 6b 65 0d 0a 23 20 64 65 73  here-like..# des
0040: 63 72 69 70 74 69 6f 6e 3a 20 57 68 65 72 65 2d  cription: Where-
0050: 6c 69 6b 65 20 66 75 6e 63 74 69 6f 6e 20 77 6f  like function wo
0060: 72 6b 73 20 61 73 20 61 20 70 69 70 65 6c 69 6e  rks as a pipelin
0070: 65 20 63 6f 6e 73 6f 6c 65 20 66 69 6c 74 65 72  e console filter
0080: 2e 0d 0a 23 20 76 65 72 73 69 6f 6e 3a 20 30 2e  ...# version: 0.
0090: 31 0d 0a 23 20 74 79 70 65 3a 20 66 75 6e 63 74  1..# type: funct
00a0: 69 6f 6e 0d 0a 23 20 61 75 74 68 6f 72 3a 20 73  ion..# author: s
00b0: 69 62 72 6f 6c 6c 65 72 0d 0a 23 20 6c 69 63 65  ibroller..# lice
00c0: 6e 73 65 3a 20 43 43 30 0d 0a 23 20 66 75 6e 63  nse: CC0..# func
00d0: 74 69 6f 6e 3a 20 57 68 65 72 65 2d 4c 69 6b 65  tion: Where-Like
00e0: 0d 0a 23 20 78 2d 70 6f 73 68 63 6f 64 65 2d 69  ..# x-poshcode-i
00f0: 64 3a 20 34 32 38 33 0d 0a 23 20 78 2d 61 72 63  d: 4283..# x-arc
0100: 68 69 76 65 64 3a 20 32 30 31 33 2d 30 37 2d 30  hived: 2013-07-0
0110: 39 54 30 34 3a 31 39 3a 35 30 0d 0a 23 20 78 2d  9T04:19:50..# x-
0120: 70 75 62 6c 69 73 68 65 64 3a 20 32 30 31 33 2d  published: 2013-
0130: 30 37 2d 30 32 54 30 38 3a 30 30 3a 30 30 0d 0a  07-02T08:00:00..
0140: 23 0d 0a 23 20 54 68 65 20 69 64 65 61 20 69 73  #..# The idea is
0150: 20 74 6f 20 66 69 6c 74 65 72 20 61 20 72 65 73   to filter a res
0160: 75 6c 74 20 6f 66 20 61 6e 79 20 63 6d 64 6c 65  ult of any cmdle
0170: 74 20 77 69 74 68 20 6c 65 73 73 20 65 66 66 6f  t with less effo
0180: 72 74 2e 0d 0a 23 20 49 2e 67 2e 20 47 65 74 2d  rt...# I.g. Get-
0190: 43 68 69 6c 64 49 74 65 6d 20 e2 80 98 43 3a 5c  ChildItem ...C:\
01a0: 57 69 6e 64 6f 77 73 e2 80 99 20 7c 20 57 68 65  Windows... | Whe
01b0: 72 65 2d 4c 69 6b 65 20 6e 61 6d 65 20 65 78 70  re-Like name exp
01c0: 6c 6f 0d 0a 23 0d 0a 66 75 6e 63 74 69 6f 6e 20  lo..#..function 
01d0: 57 68 65 72 65 2d 4c 69 6b 65 20 7b 0d 0a 09 50  Where-Like {...P
01e0: 61 72 61 6d 28 24 6d 65 6d 62 65 72 2c 20 24 73  aram($member, $s
01f0: 74 72 69 6e 67 29 0d 0a 09 70 72 6f 63 65 73 73  tring)...process
0200: 20 7b 20 24 69 6e 70 75 74 20 7c 20 77 68 65 72   { $input | wher
0210: 65 20 7b 24 5f 2e 24 6d 65 6d 62 65 72 20 2d 6c  e {$_.$member -l
0220: 69 6b 65 20 24 73 74 72 69 6e 67 7d 20 7d 20 0d  ike $string} } .
0230: 0a 7d 0d 0a                                      .}..