PoshCode Archive  Hex Artifact Content

Artifact 257825d88f513e937375b25cd0f0b624fa9d2747106f32b164d815d5ff2a7e9c:

  • File accelerators-for-posh-2.ps1 — part of check-in [0bf8c72619] at 2018-06-10 13:43:08 on branch trunk — As you know PowerShell v3 has [accelerators] type but PowerShell v2 has not this feature. So why do I have to endure this omission in PowerShell v2? (user: greg zakharov size: 638)

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 61  hell..# title: a
0030: 63 63 65 6c 65 72 61 74 6f 72 73 20 66 6f 72 20  ccelerators for 
0040: 70 6f 73 68 20 32 0d 0a 23 20 64 65 73 63 72 69  posh 2..# descri
0050: 70 74 69 6f 6e 3a 20 41 73 20 79 6f 75 20 6b 6e  ption: As you kn
0060: 6f 77 20 50 6f 77 65 72 53 68 65 6c 6c 20 76 33  ow PowerShell v3
0070: 20 68 61 73 20 5b 61 63 63 65 6c 65 72 61 74 6f   has [accelerato
0080: 72 73 5d 20 74 79 70 65 20 62 75 74 20 50 6f 77  rs] type but Pow
0090: 65 72 53 68 65 6c 6c 20 76 32 20 68 61 73 20 6e  erShell v2 has n
00a0: 6f 74 20 74 68 69 73 20 66 65 61 74 75 72 65 2e  ot this feature.
00b0: 20 53 6f 20 77 68 79 20 64 6f 20 49 20 68 61 76   So why do I hav
00c0: 65 20 74 6f 20 65 6e 64 75 72 65 20 74 68 69 73  e to endure this
00d0: 20 6f 6d 69 73 73 69 6f 6e 20 69 6e 20 50 6f 77   omission in Pow
00e0: 65 72 53 68 65 6c 6c 20 76 32 3f 0d 0a 23 20 76  erShell v2?..# v
00f0: 65 72 73 69 6f 6e 3a 20 30 2e 31 0d 0a 23 20 61  ersion: 0.1..# a
0100: 75 74 68 6f 72 3a 20 67 72 65 67 20 7a 61 6b 68  uthor: greg zakh
0110: 61 72 6f 76 0d 0a 23 20 6c 69 63 65 6e 73 65 3a  arov..# license:
0120: 20 43 43 30 0d 0a 23 20 78 2d 70 6f 73 68 63 6f   CC0..# x-poshco
0130: 64 65 2d 69 64 3a 20 34 35 36 37 0d 0a 23 20 78  de-id: 4567..# x
0140: 2d 61 72 63 68 69 76 65 64 3a 20 32 30 31 33 2d  -archived: 2013-
0150: 31 31 2d 30 31 54 30 31 3a 35 32 3a 30 33 0d 0a  11-01T01:52:03..
0160: 23 20 78 2d 70 75 62 6c 69 73 68 65 64 3a 20 32  # x-published: 2
0170: 30 31 33 2d 31 30 2d 32 38 54 30 37 3a 33 34 3a  013-10-28T07:34:
0180: 30 30 0d 0a 23 0d 0a 23 0d 0a 24 74 61 20 3d 20  00..#..#..$ta = 
0190: 5b 54 79 70 65 5d 3a 3a 47 65 74 54 79 70 65 28  [Type]::GetType(
01a0: 22 53 79 73 74 65 6d 2e 4d 61 6e 61 67 65 6d 65  "System.Manageme
01b0: 6e 74 2e 41 75 74 6f 6d 61 74 69 6f 6e 2e 54 79  nt.Automation.Ty
01c0: 70 65 41 63 63 65 6c 65 72 61 74 6f 72 73 22 29  peAccelerators")
01d0: 0d 0a 24 74 61 3a 3a 47 65 74 2e 4b 65 79 73 2e  ..$ta::Get.Keys.
01e0: 47 65 74 45 6e 75 6d 65 72 61 74 6f 72 28 29 20  GetEnumerator() 
01f0: 7c 20 25 20 7b 24 61 72 72 20 3d 20 40 28 29 7d  | % {$arr = @()}
0200: 7b 0d 0a 20 20 24 61 72 72 20 2b 3d 20 24 28 24  {..  $arr += $($
0210: 5f 20 2d 6e 65 20 27 61 63 63 65 6c 65 72 61 74  _ -ne 'accelerat
0220: 6f 72 73 27 29 0d 0a 7d 7b 0d 0a 20 20 69 66 20  ors')..}{..  if 
0230: 28 2d 6e 6f 74 20 28 24 61 72 72 20 2d 63 6f 6e  (-not ($arr -con
0240: 74 61 69 6e 73 20 27 46 61 6c 73 65 27 29 29 20  tains 'False')) 
0250: 7b 0d 0a 20 20 20 20 24 74 61 3a 3a 41 64 64 28  {..    $ta::Add(
0260: 27 61 63 63 65 6c 65 72 61 74 6f 72 73 27 2c 20  'accelerators', 
0270: 24 74 61 29 0d 0a 20 20 7d 0d 0a 7d 0d 0a        $ta)..  }..}..