PoshCode Logo PowerShell Code Repository

TabExpansion for V2CTP3 (modification of post by foobar view diff)
View followups from foobar | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1138"></script>download | new post

Ported TabExpansion from V2CTP2 to V2CTP3 and extended. Please dot souce this script file to use.

  1. ## Tab-Completion
  2. #################
  3. ## For V2CTP3.
  4. ## This won't work on V1 and V2CTP and V2CTP2.
  5. ## Please dot souce this script file.
  6. ## In first loading, it may take a several minutes, in order to generate ProgIDs and TypeNames list.
  7. ##
  8. ## What this can do is:
  9. ##
  10. ## [datetime]::n<tab>
  11. ## [datetime]::now.d<tab>
  12. ## $a = New-Object "Int32[,]" 2,3; $b = "PowerShell","PowerShell"
  13. ## $c = [ref]$a; $d = [ref]$b,$c
  14. ## $d[0].V<tab>[0][0].Get<tab>
  15. ## $d[1].V<tab>[0,0].tos<tab>
  16. ## $function:a<tab>
  17. ## $env:a<tab>
  18. ## [System.Type].a<tab>
  19. ## [datetime].Assembly.a<tab>
  20. ## ).a<tab> # shows System.Type properties and methods...
  21.  
  22. ## #native command name expansion
  23. ## fsu<tab>
  24.  
  25. ## #command option name expansion (for fsutil ipconfig net powershell only)
  26. ## fsutil <tab>
  27. ## ipconfig <tab>
  28. ## net <tab>
  29. ## powershell <tab>
  30.  
  31. ## #TypeNames and Type accelerators expansion
  32. ## [Dec<tab>
  33. ## [system.Man<tab>.auto<tab>.p<tab>
  34. ## New-Object -TypeName IO.Dir<tab>
  35. ## New-Object System.win<tab>.for<tab>.bu<tab>
  36.  
  37. ## #ProgIDs expansion
  38. ## New-Object -Com shel<tab>
  39.  
  40. ## #Enum option expansion
  41. ## Set-ExecutionPolicy <tab>
  42. ## Set-ExecutionPolicy All<tab>
  43. ## Set-ExcusionPolisy -ex <tab>
  44. ## Get-TraceSource Inte<tab>
  45. ## iex -Errora <tab> -wa Sil<tab>
  46.  
  47. ## #WmiClasses expansion
  48. ## Get-WmiObject -class Win32_<tab>
  49. ## gwmi __Instance<tab>
  50.  
  51. ## #Encoding expansion
  52. ## [Out-File | Export-CSV | Select-String | Export-Clixml] -enc <tab>
  53. ## [Add-Content | Get-Content | Set-Content} -Encoding Big<tab>
  54.  
  55. ## #PSProvider name expansion
  56. ## [Get-Location | Get-PSDrive | Get-PSProvider | New-PSDrive | Remove-PSDrive] -PSProvider <tab>
  57. ## Get-PSProvider <tab>
  58. ## pwd -psp al<tab>
  59.  
  60. ## #PSDrive name expansion
  61. ## [Get-PSDrive | New-PSDrive | Remove-PSDrive] [-Name] <tab>
  62. ## Get-PSDrive <tab>
  63. ## pwd -psd <tab>
  64.  
  65. ## #PSSnapin name expansion
  66. ## [Add-PSSnapin | Get-PSSnapin | Remove-PSSnapin ] [-Name] <tab>
  67. ## Get-Command -PSSnapin <tab>
  68. ## Remove-PSSnapin <tab>
  69. ## Get-PSSnapin M<tab>
  70.  
  71. ## #Eventlog name and expansion
  72. ## Get-Eventlog -Log <tab>
  73. ## Get-Eventlog w<tab>
  74.  
  75. ## #Eventlog's entrytype expansion
  76. ## Get-EventLog -EntryType <tab>
  77. ## Get-EventLog -EntryType Er<tab>
  78. ## Get-EventLog -Ent <tab>
  79.  
  80. ## #Service name expansion
  81. ## [Get-Service | Restart-Service | Resume-Service | Start-Service | Stop-Service | Suspend-Service] [-Name] <tab>
  82. ## New-Service -DependsOn <tab>
  83. ## New-Service -Dep e<tab>
  84. ## Get-Service -n <tab>
  85. ## Get-Service <tab>,a<tab>,p<tab>
  86. ## gsv <tab>
  87.  
  88. ## #Service display name expansion
  89. ## [Get-Service | Restart-Service | Resume-Service | Start-Service | Stop-Service | Suspend-Service] [-DisplayName] <tab>
  90. ## Get-Service -Dis <tab>
  91. ## gsv -Dis <tab>,w<tab>,b<tab>
  92.  
  93. ## #Cmdlet and Topic name expansion (this also support default help function and man alias)
  94. ## Get-Help [-Name] about_<tab>
  95. ## Get-Help <tab>
  96.  
  97. ## #Category name expansion (this also support default help function and man alias)
  98. ## Get-Help -Category c<tab>,<tab>
  99.  
  100. ## #Command name expansion
  101. ## Get-Command [-Name] <tab>
  102. ## Get-Command -Name <tab>
  103. ## gcm a<tab>,<tab>
  104.  
  105. ## #Scope expansion
  106. ## [Clear-Variable | Export-Alias | Get-Alias | Get-PSDrive | Get-Variable | Import-Alias
  107. ## New-Alias | New-PSDrive | New-Variable | Remove-Variable | Set-Alias | Set-Variable] -Scope <tab>
  108. ## Clear-Variable -Scope G<tab>
  109. ## Set-Alias  -s <tab>
  110.  
  111. ## #Process name expansion
  112. ## [Get-Process | Stop-Process] [-Name] <tab>
  113. ## Stop-Process -Name <tab>
  114. ## Stop-Process -N pow<tab>
  115. ## Get-Process <tab>
  116. ## ps power<tab>
  117.  
  118. ## #Trace sources expansion
  119. ## [Trace-Command | Get-TraceSource | Set-TraceSource] [-Name] <tab>,a<tab>,p<tab>
  120.  
  121. ## #Trace -ListenerOption expansion
  122. ## [Set-TraceSource | Trace-Command] -ListenerOption <tab>
  123. ## Set-TraceSource -Lis <tab>,n<tab>
  124.  
  125. ## #Trace -Option expansion
  126. ## [Set-TraceSource | Trace-Command] -Option <tab>
  127. ## Set-TraceSource -op <tab>,con<tab>
  128.  
  129. ## #ItemType expansion
  130. ## New-Item -Item <tab>
  131. ## ni -ItemType d<tab>
  132.  
  133. ## #ErrorAction and WarningAction option expansion
  134. ## CMDLET [-ErrorAction | -WarningAction] <tab>
  135. ## CMDLET -Errora s<tab>
  136. ## CMDLET -ea con<tab>
  137. ## CMDLET -wa <tab>
  138.  
  139. ## #Continuous expansion with comma when parameter can treat multiple option
  140. ## # if there are spaces, occur display bug in the line
  141. ## # if strings contains '$' or '-', not work
  142. ## Get-Command -CommandType <tab>,<tab><tab>,cm<tab>
  143. ## pwd -psp <tab>,f<tab>,va<tab>
  144. ## Get-EventLog -EntryType <tab>,i<tab>,s<tab>
  145.  
  146. ## #Enum expansion in method call expression
  147. ## # this needs one or more spaces after left parenthesis or comma
  148. ## $str = "day   night"
  149. ## $str.Split( " ",<space>rem<tab>
  150. ## >>> $str.Split( " ", "RemoveEmptyEntries" ) <Enter> ERROR
  151. ## $str.Split( " ", "RemoveEmptyEntries" -as<space><tab>
  152. ## >>> $str.Split( " ", "RemoveEmptyEntries" -as [System.StringSplitOptions] ) <Enter> Success
  153. ## $type = [System.Type]
  154. ## $type.GetMembers(<space>Def<tab>
  155. ## [IO.Directory]::GetFiles( "C:\", "*",<space>All<tab>
  156. ## # this can do continuous enum expansion with comma and no spaces
  157. ## $type.GetMembers( "IgnoreCase<comma>Dec<tab><comma>In<tab>"
  158. ## [IO.Directory]::GetAccessControl( "C:\",<space>au<tab><comma>ac<tab><comma>G<tab>
  159.  
  160. ## #Better '$_.' expansion when cmdlet output objects or method return objects
  161. ## ls |group { $_.Cr<tab>.Tost<tab>"y")} | tee -var foo| ? { $_.G<tab>.c<tab> -gt 5 } | % { md $_.N<tab> ; copy $_.G<tab> $_.N<tab>  }
  162. ## [IO.DriveInfo]::GetDrives() | ? { $_.A<tab> -gt 1GB }
  163. ## $Host.UI.RawUI.GetBufferContents($rect) | % { $str += $_.c<tab> }
  164. ## gcm Add-Content |select -exp Par<tab>| select -ExpandProperty Par<tab> | ? { $_.Par<tab>.N<tab> -eq "string" }
  165. ## $data = Get-Process
  166. ## $data[2,4,5]  | % { $_.<tab>
  167. ## #when Get-PipeLineObject failed, '$_.' shows methods and properties name of FileInfo and String and Type
  168.  
  169. ## #Property name expansion by -Property parameter
  170. ## [ Format-List | Format-Custom | Format-Table | Format-Wide | Compare-Object |
  171. ##  ConvertTo-Html | Measure-Object | Select-Object | Group-Object | Sort-Object ] [-Property] <tab>
  172. ## Select-Object -ExcludeProperty <tab>
  173. ## Select-Object -ExpandProperty <tab>
  174. ## gcm Get-Acl|select -exp Par<tab>
  175. ## ps |group na<tab>
  176. ## ls | ft A<tab>,M<tab>,L<tab>
  177.  
  178. ## #Hashtable key expansion in the variable name and '.<tab>'
  179. ## Get-Process | Get-Unique | % { $hash += @{$_.ProcessName=$_} }
  180. ## $hash.pow<tab>.pro<tab>
  181.  
  182. ## #Parameter expansion for function, filter and script
  183. ## man -f<tab>
  184. ## 'param([System.StringSplitOptions]$foo,[System.Management.Automation.ActionPreference]$bar,[System.Management.Automation.CommandTypes]$baz) {}' > foobar.ps1
  185. ## .\foobar.ps1 -<tab> -b<tab>
  186.  
  187. ## #Enum expansion for function, filter and scripts
  188. ## # this can do continuous enum expansion with comma and no spaces
  189. ## .\foobar.ps1 -foo rem<tab> -bar <tab><comma>c<tab><comma>sc<tab> -ea silent<tab> -wa con<tab>
  190.  
  191. ## #Enum expansion for assignment expression
  192. ## #needs space(s) after '=' and comma
  193. ## #strongly-typed with -as operator and space(s)
  194. ## $ErrorActionPreference =<space><tab>
  195. ## $cmdtypes = New-Object System.Management.Automation.CommandTypes[] 3
  196. ## $cmdtypes =<space><tab><comma><space>func<tab><comma><space>cmd<tab> -as<space><tab>
  197.  
  198. ## #Path expansion with variable and '\' or '/'
  199. ## $PWD\../../<tab>\<tab>
  200. ## "$env:SystemDrive/pro<tab>/<tab>
  201.  
  202. ## #Operator expansion which starts with '-'
  203. ## "Power","Shell" -m<tab> "Power" -r<tab> '(Pow)(er)','$1d$2'
  204. ## 1..9 -co<tab> 5
  205.  
  206. ## #Keyword expansion
  207. ## fu<tab> test { p<tab> $foo, $bar ) b<tab> "foo" } pr<tab> $_ } en<tab> "$bar" } }
  208.  
  209. ## #Variable name expansion (only global scope)
  210. ## [Clear-Variable | Get-Variable | New-Variable | Remove-Variable | Set-Variable] [-Name] <tab>
  211. ## [Cmdlet | Function | Filter | ExternalScript] -ErrorVariable <tab>
  212. ## [Cmdlet | Function | Filter | ExternalScript] -OutVariable <tab>
  213. ## Tee-Object -Variable <tab>
  214. ##  gv pro<tab>,<tab>
  215. ##  Remove-Variable -Name out<tab>,<tab>,ps<tab>
  216. ##  ... | ... | tee -v <tab>
  217.  
  218. ## #Alias name expansion
  219. ## [Get-Alias | New-Alias | Set-Alias] [-Name] <tab>
  220. ## Export-Alias -Name <tab>
  221. ##  Get-Alias i<tab>,e<tab>,a<tab>
  222. ##  epal -n for<tab>
  223.  
  224. ## #Property name expansion with -groupBy parameter
  225. ## [Format-List | Format-Custom | Format-Table | Format-Wide] -groupBy <tab>
  226. ##  ps | ft -g <tab>
  227. ##  gcm | Format-Wide -GroupBy Par<tab>
  228.  
  229. ## #Type accelerators expansion with no characters
  230. ##  [<tab>
  231. ##  New-Object -typename <tab>
  232. ##  New-Object <tab>
  233.  
  234. ## # File glob expansion with '@'
  235. ##  ls *.txt@<tab>
  236. ##  ls file.txt, foo1.txt, 'bar``[1``].txt', 'foo bar .txt'     # 1 <tab> expanding with comma
  237. ##  ls * -Filter *.txt                                          # 2 <tab> refactoring
  238. ##  ls *.txt                                                    # 3 <tab> (or 1 <tab> & 1 <shift>+<tab>) return original glob pattern
  239.  
  240. ## This can also use '^'(hat) or '~'(tilde) for Excluding
  241. ##  ls <hat>*.txt@<tab>
  242. ##  ls foo.ps1, 'bar``[1``].xml'                # 1 <tab> expanding with comma
  243. ##  ls * -Filter * -Excluding *.txt             # 2 <tab> refactoring
  244. ##  *.txt<tilde>foo*<tilde>bar*@<tab>
  245. ##  ls file.txt                                 # 1 <tab> expanding with comma
  246. ##  ls * -Filter *.txt -Excluding foo*, bar*    # 2 <tab> refactoring
  247.  
  248. ## # Ported history expansion from V2CTP3 TabExpansion with '#' ( #<pattern> or #<id> )
  249. ##  ls * -Filter * -Excluding foo*, bar*<Enter>
  250. ##  #ls<tab>
  251. ##  #1<tab>
  252.  
  253. ## # Command buffer stack with ';'(semicolon)
  254. ##  ls * -Filter * -Excluding foo*, bar*<semicolon><tab> # push command1
  255. ##  echo "PowerShell"<semicolon><tab> # push command2
  256. ##  get-process<semicolon><tab> # push command3
  257. ##  {COMMAND}<Enter> # execute another command
  258. ##  get-process # Auto pop command3 from stack by LIFO
  259. ## This can also hand-operated pop with ';,'(semicolon&comma) or ';:'(semicolon&colon)
  260. ##  get-process; <semicolon><comma><tab>
  261. ##  get-process; echo "PowerShell" # pop command2 from stack by LIFO
  262.  
  263. ## # Function name expansion after 'function' or 'filter' keywords
  264. ## function cl<tab>
  265.  
  266. ## #Switch syntax option expansion
  267. ##  switch -w<tab> -f<tab>
  268.  
  269. ## #Better powershell.exe option expansion with '-'
  270. ##  powershell -no<tab> -<tab> -en<tab>
  271.  
  272. ## #A part of PowerShell attributes expansion ( CmdletBinding, Parameter, Alias, Validate*, Allow* )
  273. ##  [par<tab>
  274. ##  [cmd<tab>
  275.  
  276. ## #Member expansion for CmdletBinding and Parameter attributes
  277. ##  [Parameter(man<tab>,<tab>1,val<tab>$true)]
  278. ##  [CmdletBinding( <tab>"foo", su<tab>$true)]
  279.  
  280. ## #Several current date/time formats with Ctrl+D
  281. ##  <Ctrl+D><tab><tab><tab><tab><tab>...
  282.  
  283. ## #Hand-operated pop from command buffer with Ctrl+P (this is also available with ';:' or ';,')
  284. ##  <command>;<tab> # push command
  285. ##  <Ctrl+D><tab> # pop
  286.  
  287. ## #Paste clipboard with Ctrl+V
  288. ##  <Ctrl+V><tab>
  289.  
  290. ## # Cut current line with Ctrl+X
  291. ##  <command><Ctrl+X><tab>
  292.  
  293. ## # Cut words with a character after Ctrl+X until the character
  294. ## 1: PS > dir -Filter *.txt<Ctrl+X>-<tab> # Cut words until '-'
  295. ## 2: PS > dir -
  296. ## 3: PS > dir -<Ctrl+V><tab> # Paste words that were copyed now
  297.  
  298. ## # Cut last word in current line with Ctrl+Z
  299. ## 1: PS >  Get-ChildItem *.txt<Ctrl+Z><tab> # Cut last word in current line
  300. ## 2: PS >  Get-ChildItem
  301. ## 3: PS >  Get-ChildItem -Exclude <Ctrl+V><tab> # Paste last word that was copyed now
  302.  
  303. ## #[ScriptBlock] member expansion for [ScriptBlock] literal
  304. ##  { 1+1 }.inv<tab>
  305.  
  306. ## #Help document's section name expansion at a line that has only spaces
  307. ##  .syn<tab>
  308. ##  .func<tab>
  309.  
  310. ## #A part of history commands expansion with Ctrl+L (using split(";"),split("|"),split(";|") )
  311. ## ls -Force -Recurse -Filter *.txt | ? { $_.LastWriteTime -lt  [DateTime]::Today } ; echo PowerShell
  312. ## ls<Ctrl+L><tab><tab>
  313. ## ?<Ctrl+L><tab><tab>
  314. ## ec<Ctrl+L><tab>
  315.  
  316. ## # Now command name expansion's priority is,
  317. ## alias -> function -> filter -> cmdlet -> script -> external command
  318.  
  319. ## # PSDrive and item name expansion in variable notation
  320. ##  ${fu<tab>
  321. ##  ${function:cl<tab>
  322. ##  ${c:*<tab>\*<tab>
  323. ##  ${c:\win<tab>/sys<tab>/<tab>
  324.  
  325. ## # Using Ctrl+K, characters insertion (bihind space or semi-coron or pipe operator) feature : it encloses tokens with parnthesis by default
  326. ##  1 - 1 - 1 - 1<Ctrl+K><tab>
  327. ##  1 - 1 - 1 - (1)<tab>
  328. ##  1 - 1 - 1 (- 1)<tab>
  329. ##  1 - 1 - (1 - 1)<tab><tab><tab>...
  330. ## with double Ctrl+K, it encloses tokens with $( )
  331. ##  for ( $i=0;$j=1<Ctrl+K><Ctrl+K><tab><tab>
  332. ##  for ( $($i=0;$j=1)
  333. ## if there is a character between <Ctrl+K> and  <tab>, it is inserted between tokens
  334. ##  1+1 | {$_*2}<Ctrl+K>%<tab>
  335. ##  1+1 | %{$_*2}
  336. ##  1+1 +1+1<Ctrl+K>;<tab>
  337. ##  1+1 ;+1+1
  338. ## if the character is ( or { or {, tokens are enclosed ( ) or { } or {}
  339. ##  int<Ctrl+K>[<tab>
  340. ##  [int]
  341. ## with double Ctrl+K, and if there is a character between <Ctrl+K> and  <tab>, it is inserted between tokens with '$'
  342. ##  C:\WINDOWS\system32\notepad.exe<Ctrl+K><Ctrl+K>{<tab>
  343. ##  ${C:\WINDOWS\system32\notepad.exe}
  344. ## % and ? are given special treatment with double Ctrl+K, these enclose tokens with % { } or ? { } behind '|'
  345. ##  ls | $_.LastWriteTime -gt "2009/5"<Ctrl+K><Ctrl+K>?<tab>
  346. ##  ls | ? {$_.LastWriteTime -gt "2009/5"}
  347. ##  ls | $_.FullName<Ctrl+K><Ctrl+K>%<tab>
  348. ##  ls | % {$_.FullName}
  349.  
  350. ### Generate ProgIDs list...
  351. if ( Test-Path $PSHOME\ProgIDs.txt )
  352. {
  353.     $_ProgID = type $PSHOME\ProgIDs.txt -ReadCount 0
  354. }
  355. else
  356. {
  357.     $_HKCR = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("CLSID\")
  358.     $_ProgID = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  359.     foreach ( $_subkey in $_HKCR.GetSubKeyNames() )
  360.     {
  361.         foreach ( $_i in [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("CLSID\$_subkey\ProgID") )
  362.         {
  363.             if ($_i -ne $null)
  364.             {
  365.                 $_ProgID.Add($_i.GetValue(""))
  366.             }
  367.         }
  368.     }
  369.     '$_ProgID was updated...' | Out-Host
  370.     $_ProgID = $_ProgID|sort -Unique
  371.  
  372.     Set-Content -Value $_ProgID -Path $PSHOME\ProgIDs.txt -Verbose
  373. }
  374.  
  375. ### Generate TypeNames list...
  376.  
  377. if ( Test-Path $PSHOME\TypeNames.txt )
  378. {
  379.     $_TypeNames = type $PSHOME\TypeNames.txt -ReadCount 0
  380. }
  381. else
  382. {
  383.     $_TypeNames = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  384.     foreach ( $_asm in [AppDomain]::CurrentDomain.GetAssemblies() )
  385.     {
  386.         foreach ( $_type in $_asm.GetTypes() )
  387.         {
  388.             $_TypeNames.Add($_type.FullName)
  389.         }
  390.     }
  391.     '$_TypeNames was updated...' | Out-Host
  392.     $_TypeNames = $_TypeNames | sort -Unique
  393.  
  394.     Set-Content -Value $_TypeNames -Path $PSHOME\TypeNames.txt -Verbose
  395. }
  396.  
  397. if ( Test-Path $PSHOME\TypeNames_System.txt )
  398. {
  399.     $_TypeNames_System = type $PSHOME\TypeNames_System.txt -ReadCount 0
  400. }
  401. else
  402. {
  403.     $_TypeNames_System = $_TypeNames -like "System.*" -replace '^System\.'
  404.     '$_TypeNames_System was updated...' | Out-Host
  405.     Set-Content -Value $_TypeNames_System -Path $PSHOME\TypeNames_System.txt -Verbose
  406. }
  407.  
  408. ### Generate WMIClasses list...
  409. if ( Test-Path $PSHOME\WMIClasses.txt )
  410. {
  411.     $_WMIClasses = type $PSHOME\WMIClasses.txt -ReadCount 0
  412. }
  413. else
  414. {
  415.     $_WMIClasses = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  416.     foreach ( $_class in gwmi -List )
  417.     {
  418.         $_WMIClasses.Add($_class.Name)
  419.     }
  420.     $_WMIClasses = $_WMIClasses | sort -Unique
  421.     '$_WMIClasses was updated...' | Out-Host
  422.     Set-Content -Value $_WMIClasses -Path $PSHOME\WMIClasses.txt -Verbose
  423. }
  424.  
  425. [Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms" ) | Out-Null
  426. $global:_cmdstack = New-Object Collections.Stack
  427. $global:_snapin = $null
  428. $global:_TypeAccelerators = [type]::gettype("System.Management.Automation.TypeAccelerators")::get.keys | sort
  429. $global:_cmdline = New-Object Collections.ArrayList
  430.  
  431.  
  432. iex (@'
  433. function prompt {
  434. h -Count 1 -OutVariable line |
  435. % { $_.CommandLine.Split("|"); $_.CommandLine.Split(";"); $_.CommandLine.Split(";"); $_.CommandLine.Split(";|") } |
  436. Get-Unique | ? { $_ -ne $line.CommandLine -and $_ -notmatch '^\s*$' } |
  437. % { $_.Trim(" ") } |
  438. ? { $global:_cmdline -notcontains $_ } | % { Set-CommandLine $_ | Out-Null }
  439. if ($_cmdstack.Count -gt 0) {
  440.    $line = $global:_cmdstack.Pop() -replace '([[\]\(\)+{}?~%])','{$1}'
  441.    [System.Windows.Forms.SendKeys]::SendWait($line)
  442. }
  443. '@ + @"
  444. ${function:prompt}
  445. }
  446. "@)
  447.  
  448. function Write-ClassNames ( $data, $i, $prefix='', $sep='.' )
  449. {
  450.     $preItem = ""
  451.     foreach ( $class in $data -like $_opt )
  452.     {
  453.         $Item = $class.Split($sep)
  454.         if ( $preItem -ne $Item[$i] )
  455.         {
  456.             if ( $i+1 -eq $Item.Count )
  457.             {
  458.                 if ( $prefix -eq "[" )
  459.                 {
  460.                     $suffix = "]"
  461.                 }
  462.                 elseif ( $sep -eq "_" )
  463.                 {
  464.                     $suffix = ""
  465.                 }
  466.                 else
  467.                 {
  468.                     $suffix = " "
  469.                 }
  470.             }
  471.             else
  472.             {
  473.                 $suffix = ""
  474.             }
  475.             $prefix + $_opt.Substring(0, $_opt.LastIndexOf($sep)+1) + $Item[$i] + $suffix
  476.  
  477.             $preItem = $Item[$i]
  478.         }
  479.     }
  480. }
  481.  
  482. function Get-PipeLineObject {
  483.  
  484.     $i = -2
  485.     $property = $null
  486.     do {
  487.         $str = $line.Split("|")
  488.         # extract the command name from the string
  489.         # first split the string into statements and pipeline elements
  490.         # This doesn't handle strings however.
  491.         $_cmdlet = [regex]::Split($str[$i], '[|;=]')[-1]
  492.  
  493.         # take the first space separated token of the remaining string
  494.         # as the command to look up. Trim any leading or trailing spaces
  495.         # so you don't get leading empty elements.
  496.         $_cmdlet = $_cmdlet.Trim().Split()[0]
  497.  
  498.         if ( $_cmdlet -eq "?" )
  499.         {
  500.             $_cmdlet = "Where-Object"
  501.         }
  502.  
  503.         $global:_exp = $_cmdlet
  504.  
  505.         # now get the info object for it...
  506.         $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet)[0]
  507.  
  508.         # loop resolving aliases...
  509.         while ($_cmdlet.CommandType -eq 'alias')
  510.         {
  511.             $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet.Definition)[0]
  512.         }
  513.  
  514.         if ( "Select-Object" -eq $_cmdlet )
  515.         {
  516.             if ( $str[$i] -match '\s+-Exp\w*[\s:]+(\w+)' )
  517.             {
  518.                 $property = $Matches[1] + ";" + $property
  519.             }
  520.         }
  521.  
  522.         $i--
  523.     } while ( "Get-Unique", "Select-Object", "Sort-Object", "Tee-Object", "Where-Object" -contains $_cmdlet )
  524.  
  525.     if ( $global:_forgci -eq $null )
  526.     {
  527.         $a = @(ls "Alias:\")[0]
  528.         $e = @(ls "Env:\")[0]
  529.         $f = @(ls "Function:\")[0]
  530.         $h = @(ls "HKCU:\")[0]
  531.         $v = @(ls "Variable:\")[0]
  532.         $c = @(ls "cert:\")[0]
  533.         $global:_forgci = gi $PSHOME\powershell.exe |
  534.         Add-Member -Name CommandType -MemberType 'NoteProperty' -Value $f.CommandType -PassThru |
  535.         Add-Member -Name Definition -MemberType 'NoteProperty' -Value $a.Definition -PassThru |
  536.         Add-Member -Name Description -MemberType 'NoteProperty' -Value $a.Description -PassThru |
  537.         Add-Member -Name Key -MemberType 'NoteProperty' -Value $e.Key -PassThru |
  538.         Add-Member -Name Location -MemberType 'NoteProperty' -Value $c.Location -PassThru |
  539.         Add-Member -Name LocationName -MemberType 'NoteProperty' -Value $c.LocationName -PassThru |
  540.         Add-Member -Name Options -MemberType 'NoteProperty' -Value $a.Options -PassThru |
  541.         Add-Member -Name ReferencedCommand -MemberType 'NoteProperty' -Value $a.ReferencedCommand -PassThru |
  542.         Add-Member -Name ResolvedCommand -MemberType 'NoteProperty' -Value $a.ResolvedCommand -PassThru |
  543.         Add-Member -Name ScriptBlock -MemberType 'NoteProperty' -Value $f.ScriptBlock -PassThru |
  544.         Add-Member -Name StoreNames -MemberType 'NoteProperty' -Value $c.StoreNames -PassThru |
  545.         Add-Member -Name SubKeyCount -MemberType 'NoteProperty' -Value $h.SubKeyCount -PassThru |
  546.         Add-Member -Name Value -MemberType 'NoteProperty' -Value $e.Value -PassThru |
  547.         Add-Member -Name ValueCount -MemberType 'NoteProperty' -Value $h.ValueCount -PassThru |
  548.         Add-Member -Name Visibility -MemberType 'NoteProperty' -Value $a.Visibility -PassThru |
  549.         Add-Member -Name Property -MemberType 'NoteProperty' -Value $h.Property -PassThru |
  550.         Add-Member -Name ResolvedCommandName -MemberType 'NoteProperty' -Value $a.ResolvedCommandName -PassThru |
  551.         Add-Member -Name Close -MemberType 'ScriptMethod' -Value {} -PassThru |
  552.         Add-Member -Name CreateSubKey -MemberType 'ScriptMethod' -Value {} -PassThru |
  553.         Add-Member -Name DeleteSubKey -MemberType 'ScriptMethod' -Value {} -PassThru |
  554.         Add-Member -Name DeleteSubKeyTree -MemberType 'ScriptMethod' -Value {} -PassThru |
  555.         Add-Member -Name DeleteValue -MemberType 'ScriptMethod' -Value {} -PassThru |
  556.         Add-Member -Name Flush -MemberType 'ScriptMethod' -Value {} -PassThru |
  557.         Add-Member -Name GetSubKeyNames -MemberType 'ScriptMethod' -Value {} -PassThru |
  558.         Add-Member -Name GetValue -MemberType 'ScriptMethod' -Value {} -PassThru |
  559.         Add-Member -Name GetValueKind -MemberType 'ScriptMethod' -Value {} -PassThru |
  560.         Add-Member -Name GetValueNames -MemberType 'ScriptMethod' -Value {} -PassThru |
  561.         Add-Member -Name IsValidValue -MemberType 'ScriptMethod' -Value {} -PassThru |
  562.         Add-Member -Name OpenSubKey -MemberType 'ScriptMethod' -Value {} -PassThru |
  563.         Add-Member -Name SetValue -MemberType 'ScriptMethod' -Value {} -PassThru
  564.     }
  565.  
  566.     if ( $global:_mix -eq $null )
  567.     {
  568.         $f = gi $PSHOME\powershell.exe
  569.         $t = [type]
  570.         $s = ""
  571.         $global:_mix = `
  572.         Add-Member -InputObject (New-Object PSObject) -Name Mode -MemberType 'NoteProperty' -Value $f.Mode -PassThru |
  573.         Add-Member -Name Assembly -MemberType 'NoteProperty' -Value $t.Assembly -PassThru |
  574.         Add-Member -Name AssemblyQualifiedName -MemberType 'NoteProperty' -Value $t.AssemblyQualifiedName -PassThru |
  575.         Add-Member -Name Attributes -MemberType 'NoteProperty' -Value $f.Attributes -PassThru |
  576.         Add-Member -Name BaseType -MemberType 'NoteProperty' -Value $t.BaseType -PassThru |
  577.         Add-Member -Name ContainsGenericParameters -MemberType 'NoteProperty' -Value $t.ContainsGenericParameters -PassThru |
  578.         Add-Member -Name CreationTime -MemberType 'NoteProperty' -Value $f.CreationTime -PassThru |
  579.         Add-Member -Name CreationTimeUtc -MemberType 'NoteProperty' -Value $f.CreationTimeUtc -PassThru |
  580.         Add-Member -Name DeclaringMethod -MemberType 'NoteProperty' -Value $t.DeclaringMethod -PassThru |
  581.         Add-Member -Name DeclaringType -MemberType 'NoteProperty' -Value $t.DeclaringType -PassThru |
  582.         Add-Member -Name Exists -MemberType 'NoteProperty' -Value $f.Exists -PassThru |
  583.         Add-Member -Name Extension -MemberType 'NoteProperty' -Value $f.Extension -PassThru |
  584.         Add-Member -Name FullName -MemberType 'NoteProperty' -Value $f.FullName -PassThru |
  585.         Add-Member -Name GenericParameterAttributes -MemberType 'NoteProperty' -Value $t.GenericParameterAttributes -PassThru |
  586.         Add-Member -Name GenericParameterPosition -MemberType 'NoteProperty' -Value $t.GenericParameterPosition -PassThru |
  587.         Add-Member -Name GUID -MemberType 'NoteProperty' -Value $t.GUID -PassThru |
  588.         Add-Member -Name HasElementType -MemberType 'NoteProperty' -Value $t.HasElementType -PassThru |
  589.         Add-Member -Name IsAbstract -MemberType 'NoteProperty' -Value $t.IsAbstract -PassThru |
  590.         Add-Member -Name IsAnsiClass -MemberType 'NoteProperty' -Value $t.IsAnsiClass -PassThru |
  591.         Add-Member -Name IsArray -MemberType 'NoteProperty' -Value $t.IsArray -PassThru |
  592.         Add-Member -Name IsAutoClass -MemberType 'NoteProperty' -Value $t.IsAutoClass -PassThru |
  593.         Add-Member -Name IsAutoLayout -MemberType 'NoteProperty' -Value $t.IsAutoLayout -PassThru |
  594.         Add-Member -Name IsByRef -MemberType 'NoteProperty' -Value $t.IsByRef -PassThru |
  595.         Add-Member -Name IsClass -MemberType 'NoteProperty' -Value $t.IsClass -PassThru |
  596.         Add-Member -Name IsCOMObject -MemberType 'NoteProperty' -Value $t.IsCOMObject -PassThru |
  597.         Add-Member -Name IsContextful -MemberType 'NoteProperty' -Value $t.IsContextful -PassThru |
  598.         Add-Member -Name IsEnum -MemberType 'NoteProperty' -Value $t.IsEnum -PassThru |
  599.         Add-Member -Name IsExplicitLayout -MemberType 'NoteProperty' -Value $t.IsExplicitLayout -PassThru |
  600.         Add-Member -Name IsGenericParameter -MemberType 'NoteProperty' -Value $t.IsGenericParameter -PassThru |
  601.         Add-Member -Name IsGenericType -MemberType 'NoteProperty' -Value $t.IsGenericType -PassThru |
  602.         Add-Member -Name IsGenericTypeDefinition -MemberType 'NoteProperty' -Value $t.IsGenericTypeDefinition -PassThru |
  603.         Add-Member -Name IsImport -MemberType 'NoteProperty' -Value $t.IsImport -PassThru |
  604.         Add-Member -Name IsInterface -MemberType 'NoteProperty' -Value $t.IsInterface -PassThru |
  605.         Add-Member -Name IsLayoutSequential -MemberType 'NoteProperty' -Value $t.IsLayoutSequential -PassThru |
  606.         Add-Member -Name IsMarshalByRef -MemberType 'NoteProperty' -Value $t.IsMarshalByRef -PassThru |
  607.         Add-Member -Name IsNested -MemberType 'NoteProperty' -Value $t.IsNested -PassThru |
  608.         Add-Member -Name IsNestedAssembly -MemberType 'NoteProperty' -Value $t.IsNestedAssembly -PassThru |
  609.         Add-Member -Name IsNestedFamANDAssem -MemberType 'NoteProperty' -Value $t.IsNestedFamANDAssem -PassThru |
  610.         Add-Member -Name IsNestedFamily -MemberType 'NoteProperty' -Value $t.IsNestedFamily -PassThru |
  611.         Add-Member -Name IsNestedFamORAssem -MemberType 'NoteProperty' -Value $t.IsNestedFamORAssem -PassThru |
  612.         Add-Member -Name IsNestedPrivate -MemberType 'NoteProperty' -Value $t.IsNestedPrivate -PassThru |
  613.         Add-Member -Name IsNestedPublic -MemberType 'NoteProperty' -Value $t.IsNestedPublic -PassThru |
  614.         Add-Member -Name IsNotPublic -MemberType 'NoteProperty' -Value $t.IsNotPublic -PassThru |
  615.         Add-Member -Name IsPointer -MemberType 'NoteProperty' -Value $t.IsPointer -PassThru |
  616.         Add-Member -Name IsPrimitive -MemberType 'NoteProperty' -Value $t.IsPrimitive -PassThru |
  617.         Add-Member -Name IsPublic -MemberType 'NoteProperty' -Value $t.IsPublic -PassThru |
  618.         Add-Member -Name IsSealed -MemberType 'NoteProperty' -Value $t.IsSealed -PassThru |
  619.         Add-Member -Name IsSerializable -MemberType 'NoteProperty' -Value $t.IsSerializable -PassThru |
  620.         Add-Member -Name IsSpecialName -MemberType 'NoteProperty' -Value $t.IsSpecialName -PassThru |
  621.         Add-Member -Name IsUnicodeClass -MemberType 'NoteProperty' -Value $t.IsUnicodeClass -PassThru |
  622.         Add-Member -Name IsValueType -MemberType 'NoteProperty' -Value $t.IsValueType -PassThru |
  623.         Add-Member -Name IsVisible -MemberType 'NoteProperty' -Value $t.IsVisible -PassThru |
  624.         Add-Member -Name LastAccessTime -MemberType 'NoteProperty' -Value $f.LastAccessTime -PassThru |
  625.         Add-Member -Name LastAccessTimeUtc -MemberType 'NoteProperty' -Value $f.LastAccessTimeUtc -PassThru |
  626.         Add-Member -Name LastWriteTime -MemberType 'NoteProperty' -Value $f.LastWriteTime -PassThru |
  627.         Add-Member -Name LastWriteTimeUtc -MemberType 'NoteProperty' -Value $f.LastWriteTimeUtc -PassThru |
  628.         Add-Member -Name MemberType -MemberType 'NoteProperty' -Value $t.MemberType -PassThru |
  629.         Add-Member -Name MetadataToken -MemberType 'NoteProperty' -Value $t.MetadataToken -PassThru |
  630.         Add-Member -Name Module -MemberType 'NoteProperty' -Value $t.Module -PassThru |
  631.         Add-Member -Name Name -MemberType 'NoteProperty' -Value $t.Name -PassThru |
  632.         Add-Member -Name Namespace -MemberType 'NoteProperty' -Value $t.Namespace -PassThru |
  633.         Add-Member -Name Parent -MemberType 'NoteProperty' -Value $f.Parent -PassThru |
  634.         Add-Member -Name ReflectedType -MemberType 'NoteProperty' -Value $t.ReflectedType -PassThru |
  635.         Add-Member -Name Root -MemberType 'NoteProperty' -Value $f.Root -PassThru |
  636.         Add-Member -Name StructLayoutAttribute -MemberType 'NoteProperty' -Value $t.StructLayoutAttribute -PassThru |
  637.         Add-Member -Name TypeHandle -MemberType 'NoteProperty' -Value $t.TypeHandle -PassThru |
  638.         Add-Member -Name TypeInitializer -MemberType 'NoteProperty' -Value $t.TypeInitializer -PassThru |
  639.         Add-Member -Name UnderlyingSystemType -MemberType 'NoteProperty' -Value $t.UnderlyingSystemType -PassThru |
  640.         Add-Member -Name PSChildName -MemberType 'NoteProperty' -Value $f.PSChildName -PassThru |
  641.         Add-Member -Name PSDrive -MemberType 'NoteProperty' -Value $f.PSDrive -PassThru |
  642.         Add-Member -Name PSIsContainer -MemberType 'NoteProperty' -Value $f.PSIsContainer -PassThru |
  643.         Add-Member -Name PSParentPath -MemberType 'NoteProperty' -Value $f.PSParentPath -PassThru |
  644.         Add-Member -Name PSPath -MemberType 'NoteProperty' -Value $f.PSPath -PassThru |
  645.         Add-Member -Name PSProvider -MemberType 'NoteProperty' -Value $f.PSProvider -PassThru |
  646.         Add-Member -Name BaseName -MemberType 'NoteProperty' -Value $f.BaseName -PassThru |
  647.         Add-Member -Name Clone -MemberType 'ScriptMethod' -Value {} -PassThru |
  648.         Add-Member -Name CompareTo -MemberType 'ScriptMethod' -Value {} -PassThru |
  649.         Add-Member -Name Contains -MemberType 'ScriptMethod' -Value {} -PassThru |
  650.         Add-Member -Name CopyTo -MemberType 'ScriptMethod' -Value {} -PassThru |
  651.         Add-Member -Name Create -MemberType 'ScriptMethod' -Value {} -PassThru |
  652.         Add-Member -Name CreateObjRef -MemberType 'ScriptMethod' -Value {} -PassThru |
  653.         Add-Member -Name CreateSubdirectory -MemberType 'ScriptMethod' -Value {} -PassThru |
  654.         Add-Member -Name Delete -MemberType 'ScriptMethod' -Value {} -PassThru |
  655.         Add-Member -Name EndsWith -MemberType 'ScriptMethod' -Value {} -PassThru |
  656.         Add-Member -Name FindInterfaces -MemberType 'ScriptMethod' -Value {} -PassThru |
  657.         Add-Member -Name FindMembers -MemberType 'ScriptMethod' -Value {} -PassThru |
  658.         Add-Member -Name GetAccessControl -MemberType 'ScriptMethod' -Value {} -PassThru |
  659.         Add-Member -Name GetArrayRank -MemberType 'ScriptMethod' -Value {} -PassThru |
  660.         Add-Member -Name GetConstructor -MemberType 'ScriptMethod' -Value {} -PassThru |
  661.         Add-Member -Name GetConstructors -MemberType 'ScriptMethod' -Value {} -PassThru |
  662.         Add-Member -Name GetCustomAttributes -MemberType 'ScriptMethod' -Value {} -PassThru |
  663.         Add-Member -Name GetDefaultMembers -MemberType 'ScriptMethod' -Value {} -PassThru |
  664.         Add-Member -Name GetDirectories -MemberType 'ScriptMethod' -Value {} -PassThru |
  665.         Add-Member -Name GetElementType -MemberType 'ScriptMethod' -Value {} -PassThru |
  666.         Add-Member -Name GetEnumerator -MemberType 'ScriptMethod' -Value {} -PassThru |
  667.         Add-Member -Name GetEvent -MemberType 'ScriptMethod' -Value {} -PassThru |
  668.         Add-Member -Name GetEvents -MemberType 'ScriptMethod' -Value {} -PassThru |
  669.         Add-Member -Name GetField -MemberType 'ScriptMethod' -Value {} -PassThru |
  670.         Add-Member -Name GetFields -MemberType 'ScriptMethod' -Value {} -PassThru |
  671.         Add-Member -Name GetFiles -MemberType 'ScriptMethod' -Value {} -PassThru |
  672.         Add-Member -Name GetFileSystemInfos -MemberType 'ScriptMethod' -Value {} -PassThru |
  673.         Add-Member -Name GetGenericArguments -MemberType 'ScriptMethod' -Value {} -PassThru |
  674.         Add-Member -Name GetGenericParameterConstraints -MemberType 'ScriptMethod' -Value {} -PassThru |
  675.         Add-Member -Name GetGenericTypeDefinition -MemberType 'ScriptMethod' -Value {} -PassThru |
  676.         Add-Member -Name GetInterface -MemberType 'ScriptMethod' -Value {} -PassThru |
  677.         Add-Member -Name GetInterfaceMap -MemberType 'ScriptMethod' -Value {} -PassThru |
  678.         Add-Member -Name GetInterfaces -MemberType 'ScriptMethod' -Value {} -PassThru |
  679.         Add-Member -Name GetLifetimeService -MemberType 'ScriptMethod' -Value {} -PassThru |
  680.         Add-Member -Name GetMember -MemberType 'ScriptMethod' -Value {} -PassThru |
  681.         Add-Member -Name GetMembers -MemberType 'ScriptMethod' -Value {} -PassThru |
  682.         Add-Member -Name GetMethod -MemberType 'ScriptMethod' -Value {} -PassThru |
  683.         Add-Member -Name GetMethods -MemberType 'ScriptMethod' -Value {} -PassThru |
  684.         Add-Member -Name GetNestedType -MemberType 'ScriptMethod' -Value {} -PassThru |
  685.         Add-Member -Name GetNestedTypes -MemberType 'ScriptMethod' -Value {} -PassThru |
  686.         Add-Member -Name GetObjectData -MemberType 'ScriptMethod' -Value {} -PassThru |
  687.         Add-Member -Name GetProperties -MemberType 'ScriptMethod' -Value {} -PassThru |
  688.         Add-Member -Name GetProperty -MemberType 'ScriptMethod' -Value {} -PassThru |
  689.         Add-Member -Name GetTypeCode -MemberType 'ScriptMethod' -Value {} -PassThru |
  690.         Add-Member -Name IndexOf -MemberType 'ScriptMethod' -Value {} -PassThru |
  691.         Add-Member -Name IndexOfAny -MemberType 'ScriptMethod' -Value {} -PassThru |
  692.         Add-Member -Name InitializeLifetimeService -MemberType 'ScriptMethod' -Value {} -PassThru |
  693.         Add-Member -Name Insert -MemberType 'ScriptMethod' -Value {} -PassThru |
  694.         Add-Member -Name InvokeMember -MemberType 'ScriptMethod' -Value {} -PassThru |
  695.         Add-Member -Name IsAssignableFrom -MemberType 'ScriptMethod' -Value {} -PassThru |
  696.         Add-Member -Name IsDefined -MemberType 'ScriptMethod' -Value {} -PassThru |
  697.         Add-Member -Name IsInstanceOfType -MemberType 'ScriptMethod' -Value {} -PassThru |
  698.         Add-Member -Name IsNormalized -MemberType 'ScriptMethod' -Value {} -PassThru |
  699.         Add-Member -Name IsSubclassOf -MemberType 'ScriptMethod' -Value {} -PassThru |
  700.         Add-Member -Name LastIndexOf -MemberType 'ScriptMethod' -Value {} -PassThru |
  701.         Add-Member -Name LastIndexOfAny -MemberType 'ScriptMethod' -Value {} -PassThru |
  702.         Add-Member -Name MakeArrayType -MemberType 'ScriptMethod' -Value {} -PassThru |
  703.         Add-Member -Name MakeByRefType -MemberType 'ScriptMethod' -Value {} -PassThru |
  704.         Add-Member -Name MakeGenericType -MemberType 'ScriptMethod' -Value {} -PassThru |
  705.         Add-Member -Name MakePointerType -MemberType 'ScriptMethod' -Value {} -PassThru |
  706.         Add-Member -Name MoveTo -MemberType 'ScriptMethod' -Value {} -PassThru |
  707.         Add-Member -Name Normalize -MemberType 'ScriptMethod' -Value {} -PassThru |
  708.         Add-Member -Name PadLeft -MemberType 'ScriptMethod' -Value {} -PassThru |
  709.         Add-Member -Name PadRight -MemberType 'ScriptMethod' -Value {} -PassThru |
  710.         Add-Member -Name Refresh -MemberType 'ScriptMethod' -Value {} -PassThru |
  711.         Add-Member -Name Remove -MemberType 'ScriptMethod' -Value {} -PassThru |
  712.         Add-Member -Name Replace -MemberType 'ScriptMethod' -Value {} -PassThru |
  713.         Add-Member -Name SetAccessControl -MemberType 'ScriptMethod' -Value {} -PassThru |
  714.         Add-Member -Name Split -MemberType 'ScriptMethod' -Value {} -PassThru |
  715.         Add-Member -Name StartsWith -MemberType 'ScriptMethod' -Value {} -PassThru |
  716.         Add-Member -Name Substring -MemberType 'ScriptMethod' -Value {} -PassThru |
  717.         Add-Member -Name ToCharArray -MemberType 'ScriptMethod' -Value {} -PassThru |
  718.         Add-Member -Name ToLower -MemberType 'ScriptMethod' -Value {} -PassThru |
  719.         Add-Member -Name ToLowerInvariant -MemberType 'ScriptMethod' -Value {} -PassThru |
  720.         Add-Member -Name ToUpper -MemberType 'ScriptMethod' -Value {} -PassThru |
  721.         Add-Member -Name ToUpperInvariant -MemberType 'ScriptMethod' -Value {} -PassThru |
  722.         Add-Member -Name Trim -MemberType 'ScriptMethod' -Value {} -PassThru |
  723.         Add-Member -Name TrimEnd -MemberType 'ScriptMethod' -Value {} -PassThru |
  724.         Add-Member -Name TrimStart -MemberType 'ScriptMethod' -Value {} -PassThru |
  725.         Add-Member -Name Chars -MemberType 'NoteProperty' -Value $s.Chars -PassThru
  726.     }
  727.  
  728.  
  729.     if ( "Add-Member" -eq $_cmdlet )
  730.     {
  731.         $global:_dummy = $null
  732.     }
  733.  
  734.  
  735.     if ( "Compare-Object" -eq $_cmdlet )
  736.     {
  737.         $global:_dummy =  (Compare-Object 1 2)[0]
  738.     }
  739.  
  740.  
  741.     if ( "ConvertFrom-SecureString" -eq $_cmdlet )
  742.     {
  743.         $global:_dummy = $null
  744.     }
  745.  
  746.  
  747.     if ( "ConvertTo-SecureString" -eq $_cmdlet )
  748.     {
  749.         $global:_dummy = convertto-securestring "P@ssW0rD!" -asplaintext -force
  750.     }
  751.  
  752.  
  753.     if ( "ForEach-Object" -eq $_cmdlet )
  754.     {
  755.         $global:_dummy = $null
  756.     }
  757.  
  758.  
  759.     if ( "Get-Acl" -eq $_cmdlet )
  760.     {
  761.         $global:_dummy = Get-Acl
  762.     }
  763.  
  764.  
  765.     if ( "Get-Alias" -eq $_cmdlet )
  766.     {
  767.         $global:_dummy = (Get-Alias)[0]
  768.     }
  769.  
  770.  
  771.     if ( "Get-AuthenticodeSignature" -eq $_cmdlet )
  772.     {
  773.         $global:_dummy = Get-AuthenticodeSignature $PSHOME\powershell.exe
  774.     }
  775.  
  776.  
  777.     if ( "Get-ChildItem" -eq $_cmdlet )
  778.     {
  779.         $global:_dummy = $global:_forgci
  780.     }
  781.  
  782.  
  783.     if ( "Get-Command" -eq $_cmdlet )
  784.     {
  785.         $global:_dummy = @(iex $str[$i+1])[0]
  786.     }
  787.  
  788.  
  789.     if ( "Get-Content" -eq $_cmdlet )
  790.     {
  791.         $global:_dummy = (type $PSHOME\profile.ps1)[0]
  792.     }
  793.  
  794.  
  795.     if ( "Get-Credential" -eq $_cmdlet )
  796.     {
  797.         $global:_dummy = $null
  798.     }
  799.  
  800.  
  801.     if ( "Get-Culture" -eq $_cmdlet )
  802.     {
  803.         $global:_dummy = Get-Culture
  804.     }
  805.  
  806.  
  807.     if ( "Get-Date" -eq $_cmdlet )
  808.     {
  809.         $global:_dummy = Get-Date
  810.     }
  811.  
  812.  
  813.     if ( "Get-Event" -eq $_cmdlet )
  814.     {
  815.         $global:_dummy = (Get-Event)[0]
  816.     }
  817.  
  818.  
  819.     if ( "Get-EventLog" -eq $_cmdlet )
  820.     {
  821.         $global:_dummy = @(iex $str[$i+1])[0]
  822.     }
  823.  
  824.  
  825.     if ( "Get-ExecutionPolicy" -eq $_cmdlet )
  826.     {
  827.         $global:_dummy = Get-ExecutionPolicy
  828.     }
  829.  
  830.  
  831.     if ( "Get-Help" -eq $_cmdlet )
  832.     {
  833.         $global:_dummy = Get-Help Add-Content
  834.     }
  835.  
  836.  
  837.     if ( "Get-History" -eq $_cmdlet )
  838.     {
  839.         $global:_dummy = Get-History -Count 1
  840.     }
  841.  
  842.  
  843.     if ( "Get-Host" -eq $_cmdlet )
  844.     {
  845.         $global:_dummy = Get-Host
  846.     }
  847.  
  848.  
  849.     if ( "Get-Item" -eq $_cmdlet )
  850.     {
  851.         $global:_dummy = $global:_forgci
  852.     }
  853.  
  854.  
  855.     if ( "Get-ItemProperty" -eq $_cmdlet )
  856.     {
  857.         $global:_dummy = $null
  858.     }
  859.  
  860.  
  861.     if ( "Get-Location" -eq $_cmdlet )
  862.     {
  863.         $global:_dummy = Get-Location
  864.     }
  865.  
  866.  
  867.     if ( "Get-Member" -eq $_cmdlet )
  868.     {
  869.         $global:_dummy = (1|Get-Member)[0]
  870.     }
  871.  
  872.  
  873.     if ( "Get-Module" -eq $_cmdlet )
  874.     {
  875.         $global:_dummy = (Get-Module)[0]
  876.     }
  877.  
  878.  
  879.     if ( "Get-PfxCertificate" -eq $_cmdlet )
  880.     {
  881.         $global:_dummy = $null
  882.     }
  883.  
  884.  
  885.     if ( "Get-Process" -eq $_cmdlet )
  886.     {
  887.         $global:_dummy = ps powershell
  888.     }
  889.  
  890.  
  891.     if ( "Get-PSBreakpoint" -eq $_cmdlet )
  892.     {
  893.         $global:_dummy =
  894.         Add-Member -InputObject (New-Object PSObject) -Name Action -MemberType 'NoteProperty' -Value '' -PassThru |
  895.         Add-Member -Name Command -MemberType 'NoteProperty' -Value '' -PassThru |
  896.         Add-Member -Name Enabled -MemberType 'NoteProperty' -Value '' -PassThru |
  897.         Add-Member -Name HitCount -MemberType 'NoteProperty' -Value '' -PassThru |
  898.         Add-Member -Name Id -MemberType 'NoteProperty' -Value '' -PassThru |
  899.         Add-Member -Name Script -MemberType 'NoteProperty' -Value '' -PassThru
  900.     }
  901.  
  902.  
  903.     if ( "Get-PSCallStack" -eq $_cmdlet )
  904.     {
  905.         $global:_dummy = Get-PSCallStack
  906.     }
  907.  
  908.  
  909.     if ( "Get-PSDrive" -eq $_cmdlet )
  910.     {
  911.         $global:_dummy = Get-PSDrive Function
  912.     }
  913.  
  914.  
  915.     if ( "Get-PSProvider" -eq $_cmdlet )
  916.     {
  917.         $global:_dummy = Get-PSProvider FileSystem
  918.     }
  919.  
  920.  
  921.     if ( "Get-PSSnapin" -eq $_cmdlet )
  922.     {
  923.         $global:_dummy = Get-PSSnapin Microsoft.PowerShell.Core
  924.     }
  925.  
  926.  
  927.     if ( "Get-Service" -eq $_cmdlet )
  928.     {
  929.         $global:_dummy = (Get-Service)[0]
  930.     }
  931.  
  932.  
  933.     if ( "Get-TraceSource" -eq $_cmdlet )
  934.     {
  935.         $global:_dummy = Get-TraceSource AddMember
  936.     }
  937.  
  938.  
  939.     if ( "Get-UICulture" -eq $_cmdlet )
  940.     {
  941.         $global:_dummy = Get-UICulture
  942.     }
  943.  
  944.  
  945.     if ( "Get-Variable" -eq $_cmdlet )
  946.     {
  947.         $global:_dummy = Get-Variable _
  948.     }
  949.  
  950.  
  951.     if ( "Get-WmiObject" -eq $_cmdlet )
  952.     {
  953.         $global:_dummy = @(iex $str[$i+1])[0]
  954.     }
  955.  
  956.  
  957.     if ( "Group-Object" -eq $_cmdlet )
  958.     {
  959.         $global:_dummy = 1 | group
  960.     }
  961.  
  962.  
  963.     if ( "Measure-Command" -eq $_cmdlet )
  964.     {
  965.         $global:_dummy = Measure-Command {}
  966.     }
  967.  
  968.  
  969.     if ( "Measure-Object" -eq $_cmdlet )
  970.     {
  971.         $global:_dummy = Measure-Object
  972.     }
  973.  
  974.  
  975.     if ( "New-PSDrive" -eq $_cmdlet )
  976.     {
  977.         $global:_dummy =  Get-PSDrive Alias
  978.     }
  979.  
  980.  
  981.     if ( "New-TimeSpan" -eq $_cmdlet )
  982.     {
  983.         $global:_dummy = New-TimeSpan
  984.     }
  985.  
  986.  
  987.     if ( "Resolve-Path" -eq $_cmdlet )
  988.     {
  989.         $global:_dummy = $PWD
  990.     }
  991.  
  992.  
  993.     if ( "Select-String" -eq $_cmdlet )
  994.     {
  995.         $global:_dummy = " " | Select-String " "
  996.     }
  997.  
  998.  
  999.     if ( "Set-Date" -eq $_cmdlet )
  1000.     {
  1001.         $global:_dummy =  Get-Date
  1002.     }
  1003.  
  1004.     if ( $property -ne $null)
  1005.     {
  1006.         foreach ( $name in $property.Split(";", "RemoveEmptyEntries" -as [System.StringSplitOptions]) )
  1007.         {
  1008.         $global:_dummy = @($global:_dummy.$name)[0]
  1009.         }
  1010.     }
  1011. }
  1012.  
  1013. function Set-CommandLine ( [string]$script ) { $global:_cmdline.Add($script) }
  1014.  
  1015. function Get-CommandLine ( [string]$name ) {
  1016. $name = $name -replace '\?','`?'
  1017. $global:_cmdline -like "$name*"
  1018. }
  1019.  
  1020. function TabExpansion {
  1021.             # This is the default function to use for tab expansion. It handles simple
  1022.             # member expansion on variables, variable name expansion and parameter completion
  1023.             # on commands. It doesn't understand strings so strings containing ; | ( or { may
  1024.             # cause expansion to fail.
  1025.  
  1026.             param($line, $lastWord)
  1027.  
  1028.             & {
  1029.                 # Helper function to write out the matching set of members. It depends
  1030.                 # on dynamic scoping to get $_base, _$expression and $_pat
  1031.                 function Write-Members ($sep='.')
  1032.                 {
  1033.                     # evaluate the expression to get the object to examine...
  1034.                     Invoke-Expression ('$_val=' + $_expression)
  1035.  
  1036.                     if ( $_expression -match '^\$global:_dummy' )
  1037.                     {
  1038.                         $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1039.                         $_expression = '$_' + $temp
  1040.                     }
  1041.  
  1042.                     $_method = [Management.Automation.PSMemberTypes] `
  1043.                         'Method,CodeMethod,ScriptMethod,ParameterizedProperty'
  1044.                     if ($sep -eq '.')
  1045.                     {
  1046.                         $params = @{view = 'extended','adapted','base'}
  1047.                     }
  1048.                     else
  1049.                     {
  1050.                         $params = @{static=$true}
  1051.                     }
  1052.  
  1053.                     if ( $_val -is [Hashtable] )
  1054.                     {
  1055.                         [Object[]]$_keys = $null
  1056.                         foreach ( $_name in $_val.Keys )
  1057.                         {
  1058.                             $_keys += `
  1059.                             New-Object Microsoft.PowerShell.Commands.MemberDefinition `
  1060.                             [int],$_name,"Property",0
  1061.                         }
  1062.                     }
  1063.  
  1064.                     if ( $_keys -ne $null )
  1065.                     {
  1066.                         $_members = [Object[]](Get-Member @params -InputObject $_val $_pat) + ($_keys | ? {$_.name -like $_pat})
  1067.                     } else {
  1068.                         $_members = (Get-Member @params -InputObject $_val $_pat)
  1069.                     }
  1070.  
  1071.                     foreach ($_m in $_members | Sort-Object membertype,name)
  1072.                     {
  1073.                         if ($_m.MemberType -band $_method)
  1074.                         {
  1075.                             # Return a method...
  1076.                             $_base + $_expression + $sep + $_m.name + '('
  1077.                         }
  1078.                         else {
  1079.                             # Return a property...
  1080.                             $_base + $_expression + $sep + $_m.name
  1081.                         }
  1082.                     }
  1083.                 }
  1084.  
  1085.                 switch ([int]$line[-1])
  1086.                 {
  1087.                     # Ctrl+D several date/time formats
  1088.                     4 {
  1089.                         "[DateTime]::Now"
  1090.                         [DateTime]::Now
  1091.                         [DateTime]::Now.ToString("yyyyMMdd")
  1092.                         [DateTime]::Now.ToString("MMddyyyy")
  1093.                         [DateTime]::Now.ToString("yyyyMMddHHmmss")
  1094.                         [DateTime]::Now.ToString("MMddyyyyHHmmss")
  1095.                         'd f g m o r t u y'.Split(" ") | % { [DateTime]::Now.ToString($_) }
  1096.                         break;
  1097.                     }
  1098.  
  1099.                     # Ctrl+K put parentheses behind space or semi-coron or pipe operator
  1100.                     11 {
  1101.                         if ( $line -ne $( "=" + [Char]11 ) )
  1102.                         {
  1103.                             if ( $line[-2] -eq 11 )
  1104.                             {
  1105.                                 $left = '$' + "("
  1106.                                 $line = $line.Substring(0,$line.length-2)
  1107.                             }
  1108.                             else
  1109.                             {
  1110.                                 $left = "("
  1111.                                 $line = $line.Substring(0,$line.length-1)
  1112.                             }
  1113.  
  1114.                             $global:_ctrlk = @()
  1115.                             $l = $line.Length
  1116.                             while ( $l -ge 0 )
  1117.                             {
  1118.                                 $i = $line.Substring(0,$l).LastIndexOfAny(" ;|")
  1119.                                 $global:_ctrlk += $line.Insert($i+1, $left) + ")"
  1120.                                 $l = $i
  1121.                             }
  1122.                             $global:_ctrlk += $line
  1123.                             [Windows.Forms.SendKeys]::SendWait("{Esc}=^K{TAB}")
  1124.                         }
  1125.                         else {
  1126.                             $global:_ctrlk
  1127.                         }
  1128.                         break TabExpansion;
  1129.                     }
  1130.  
  1131.                     # Ctrl+L a part of history commands expansion
  1132.                     12 {
  1133.                         Get-CommandLine $lastWord.SubString(0, $lastword.Length-1)
  1134.                         break;
  1135.                     }
  1136.  
  1137.                     # Ctrl+P hand-operated pop from command buffer stack
  1138.                     16 {
  1139.                         $_base = $lastword.SubString(0, $lastword.Length-1)
  1140.                         $_base + $global:_cmdstack.Pop()
  1141.                         break;
  1142.                     }
  1143.  
  1144.                     # Ctrl+R $Host.UI.RawUI.
  1145.                     18 {
  1146.                         '$Host.UI.RawUI.'
  1147.                         '$Host.UI.RawUI'
  1148.                         break;
  1149.                     }
  1150.  
  1151.                     # Ctrl+V paste clipboard
  1152.                     22 {
  1153.                         $_base = $lastword.SubString(0, $lastword.Length-1)
  1154.                         $_clip = New-Object System.Windows.Forms.TextBox
  1155.                         $_clip.Multiline = $true
  1156.                         $_clip.Paste()
  1157.                         $_base + $_clip.Text
  1158.                         break;
  1159.                     }
  1160.  
  1161.                     # Ctrl+X cut current line
  1162.                     24 {
  1163.                         $_clip = new-object System.Windows.Forms.TextBox;
  1164.                         $_clip.Multiline = $true;
  1165.                         $_clip.Text = $line.SubString(0, $line.Length-1)
  1166.                         $_clip.SelectAll()
  1167.                         $_clip.Copy()
  1168.                         [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1169.                         break;
  1170.                     }
  1171.  
  1172.                     # Ctrl+Z cut last word in current line
  1173.                     26 {
  1174.                         $line.SubString(0, $line.Length-1) -match '(^(.*\s)([^\s]*)$)|(^[^\s]*$)' | Out-Null
  1175.                         $_clip = new-object System.Windows.Forms.TextBox;
  1176.                         $_clip.Multiline = $true;
  1177.                         $_clip.Text = $Matches[3]
  1178.                         $_clip.SelectAll()
  1179.                         $_clip.Copy()
  1180.                         [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1181.                         $line = $Matches[2] -replace '([[\]\(\)+{}?~%])','{$1}'
  1182.                         [System.Windows.Forms.SendKeys]::SendWait($line)
  1183.                         break;
  1184.                     }
  1185.                 }
  1186.  
  1187.                 switch ( [int]$line[-2] )
  1188.                 {
  1189.                     # Ctrl+K put character behind space or semi-coron or pipe operator
  1190.                     11 {
  1191.                         switch ( $line[-1] )
  1192.                         {
  1193.                             '{' { $right = '}' }
  1194.                             '(' { $right = ')' }
  1195.                             '[' { $right = ']' }
  1196.                         }
  1197.  
  1198.                         $left = $line[-1]
  1199.                         $delimiter = " ;|"
  1200.  
  1201.                         if ( $line[-3] -eq 11 )
  1202.                         {
  1203.                             if ( $line[-1] -eq '%' -or $line[-1] -eq '?' )
  1204.                             {
  1205.                                 $left = ' ' + $left + ' {'; $right = '}'
  1206.                                 $delimiter = '|'
  1207.                             }
  1208.                             else
  1209.                             {
  1210.                                 $left = '$' + $left
  1211.                             }
  1212.                             $line = $line.Substring(0,$line.length-3)
  1213.                         }
  1214.                         else
  1215.                         {
  1216.                             $line = $line.Substring(0,$line.length-2)
  1217.                         }
  1218.  
  1219.                         $global:_ctrlk = @()
  1220.                         $l = $line.Length
  1221.                         while ( $l -ge 0 )
  1222.                         {
  1223.                             $i = $line.Substring(0,$l).LastIndexOfAny($delimiter)
  1224.                             $global:_ctrlk += $line.Insert($i+1, $left) + $right
  1225.                             $l = $i
  1226.                         }
  1227.                         $global:_ctrlk += $line
  1228.                         [Windows.Forms.SendKeys]::SendWait("{Esc}=^K{TAB}")
  1229.                         break TabExpansion;
  1230.                     }
  1231.  
  1232.                     # Ctrl+X cut words with a character after Ctrl+X until the character
  1233.                     24 {
  1234.                         $line.SubString(0, $line.Length-2) -match "(^(.*$($line[-1]))([^$($line[-1])]*)`$)|(^[^\$($line[-1])]*`$)" | Out-Null
  1235.                         $_clip = new-object System.Windows.Forms.TextBox;
  1236.                         $_clip.Multiline = $true;
  1237.                         $_clip.Text = $Matches[3]
  1238.                         $_clip.SelectAll()
  1239.                         $_clip.Copy()
  1240.                         [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1241.                         $line = $Matches[2] -replace '([[\]\(\)+{}?~%])','{$1}'
  1242.                         [System.Windows.Forms.SendKeys]::SendWait($line)
  1243.                         break;
  1244.                     }
  1245.                 }
  1246.  
  1247.  
  1248.                 switch -regex ($lastWord)
  1249.                 {
  1250.                     # Handle property and method expansion at '$_'
  1251.                     '(^.*)(\$_\.)(\w*)$' {
  1252.                         $_base = $matches[1]
  1253.                         $_expression = '$global:_dummy'
  1254.                         $_pat = $matches[3] + '*'
  1255.                         $global:_dummy = $null
  1256.                         Get-PipeLineObject
  1257.                         if ( $global:_dummy -eq $null )
  1258.                         {
  1259.                             if ( $global:_exp -match '^\$.*\(.*$' )
  1260.                             {
  1261.                                 $type = ( iex $global:_exp.Split("(")[0] ).OverloadDefinitions[0].Split(" ")[0] -replace '\[[^\[\]]*\]$' -as [type]
  1262.  
  1263.                                 if ( $_expression -match '^\$global:_dummy' )
  1264.                                 {
  1265.                                     $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1266.                                     $_expression = '$_' + $temp
  1267.                                 }
  1268.  
  1269.                                 foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1270.                                 {
  1271.                                    if ($_m.MemberType -eq "Method")
  1272.                                    {
  1273.                                        $_base + $_expression + '.' + $_m.name + '('
  1274.                                    }
  1275.                                    else {
  1276.                                        $_base + $_expression + '.' + $_m.name
  1277.                                    }
  1278.                                 }
  1279.                                 break;
  1280.                             }
  1281.                             elseif ( $global:_exp -match '^\[.*\:\:.*\(.*$' )
  1282.                             {
  1283.                                 $tname, $mname = $_exp.Split(":(", "RemoveEmptyEntries"-as [System.StringSplitOptions])[0,1]
  1284.                                 $type = @(iex ($tname + '.GetMember("' + $mname + '")'))[0].ReturnType.FullName -replace '\[[^\[\]]*\]$' -as [type]
  1285.  
  1286.                                 if ( $_expression -match '^\$global:_dummy' )
  1287.                                 {
  1288.                                     $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1289.                                     $_expression = '$_' + $temp
  1290.                                 }
  1291.  
  1292.                                 foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1293.                                 {
  1294.                                    if ($_m.MemberType -eq "Method")
  1295.                                    {
  1296.                                        $_base + $_expression + '.' + $_m.name + '('
  1297.                                    }
  1298.                                    else {
  1299.                                        $_base + $_expression + '.' + $_m.name
  1300.                                    }
  1301.                                 }
  1302.                                 break;
  1303.                             }
  1304.                             elseif ( $global:_exp -match '^(\$\w+(\[[0-9,\.]+\])*(\.\w+(\[[0-9,\.]+\])*)*)$' )
  1305.                             {
  1306.                                 $global:_dummy = @(iex $Matches[1])[0]
  1307.                             }
  1308.                             else
  1309.                             {
  1310.                                 $global:_dummy =  $global:_mix
  1311.                             }
  1312.                         }
  1313.  
  1314.                         Write-Members
  1315.                         break;
  1316.                     }
  1317.  
  1318.                     # Handle property and method expansion rooted at variables...
  1319.                     # e.g. $a.b.<tab>
  1320.                     '(^.*)(\$(\w|\.)+)\.(\w*)$' {
  1321.                         $_base = $matches[1]
  1322.                         $_expression = $matches[2]
  1323.                         $_pat = $matches[4] + '*'
  1324.                         [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1325.                         if ( $_expression -match '^\$_\.' )
  1326.                         {
  1327.                             $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1328.                         }
  1329.                         Write-Members
  1330.                         break;
  1331.                     }
  1332.  
  1333.                     # Handle simple property and method expansion on static members...
  1334.                     # e.g. [datetime]::n<tab>
  1335.                     '(^.*)(\[(\w|\.)+\])\:\:(\w*)$' {
  1336.                         $_base = $matches[1]
  1337.                         $_expression = $matches[2]
  1338.                         $_pat = $matches[4] + '*'
  1339.                         Write-Members '::'
  1340.                         break;
  1341.                     }
  1342.  
  1343.                     # Handle complex property and method expansion on static members
  1344.                     # where there are intermediate properties...
  1345.                     # e.g. [datetime]::now.d<tab>
  1346.                     '(^.*)(\[(\w|\.)+\]\:\:(\w+\.)+)(\w*)$' {
  1347.                         $_base = $matches[1]  # everything before the expression
  1348.                         $_expression = $matches[2].TrimEnd('.') # expression less trailing '.'
  1349.                         $_pat = $matches[5] + '*'  # the member to look for...
  1350.                         Write-Members
  1351.                         break;
  1352.                     }
  1353.  
  1354.                     # Handle property and method expansion on [ScriptBlock] members...
  1355.                     # e.g. { 1+1 }.inv<tab>
  1356.                     '(^.*})\.(\w*)$' {
  1357.                         $_base = $matches[1]
  1358.                         $_pat = $matches[2] + '*'
  1359.                         foreach ( $_m in {} | Get-Member $_pat | sort membertype,name )
  1360.                         {
  1361.                             if ($_m.MemberType -eq "Method")
  1362.                             {
  1363.                                 $_base + '.' + $_m.name + '('
  1364.                             }
  1365.                             else {
  1366.                                 $_base + '.' + $_m.name
  1367.                             }
  1368.                         }
  1369.                         break;
  1370.                     }
  1371.  
  1372.                     # Handle variable name expansion...
  1373.                     '(^.*\$)(\w+)$' {
  1374.                         $_prefix = $matches[1]
  1375.                         $_varName = $matches[2]
  1376.                         foreach ($_v in Get-ChildItem ('variable:' + $_varName + '*'))
  1377.                         {
  1378.                             $_prefix + $_v.name
  1379.                         }
  1380.                         break;
  1381.                     }
  1382.  
  1383.                     # Handle item name expansion in variable notation...
  1384.                     '(^.*\${)(((\w+):([\\/]?))[^\\/]+([\\/][^\\/]*)*)$' {
  1385.                         $_prefix = $matches[1]
  1386.                         $_driveName = $matches[3]
  1387.                         $_itemName = $matches[2] + "*"
  1388.                         Get-ChildItem $_itemName  |
  1389.                         % {
  1390.                             if ( $matches[5] -and $_.PSProvider.Name -eq "FileSystem" )
  1391.                             {
  1392.                                 $output = $_prefix + $_.FullName
  1393.                             }
  1394.                             elseif ( $_.PSProvider.Name -eq "FileSystem" -and $matches[6] )
  1395.                             {
  1396.                                 $cd = (Get-Location -PSDrive $matches[4]).Path
  1397.                                 $output = $_prefix + $_driveName + $_.FullName.Substring($cd.Length+1)
  1398.                             }
  1399.                             elseif ( $_.PSProvider.Name -eq "FileSystem" )
  1400.                             {
  1401.                                 $cd = (Get-Location -PSDrive $matches[4]).Path
  1402.                                 $output = $_prefix + $_driveName + $_.FullName.Substring($cd.Length+1)
  1403.                             }
  1404.                             else
  1405.                             {
  1406.                                 $output = $_prefix + $_driveName + $_.Name
  1407.                             }
  1408.  
  1409.                             if ( $_.PSIsContainer )
  1410.                             {
  1411.                                 $output
  1412.                             }
  1413.                             else
  1414.                             {
  1415.                                 $output + "}"
  1416.                             }
  1417.                         }
  1418.                         break;
  1419.                     }
  1420.  
  1421.                     # Handle PSDrive name expansion in variable notation...
  1422.                     '(^.*\${)(\w+)$' {
  1423.                         $_prefix = $matches[1]
  1424.                         $_driveName = $matches[2] + "*"
  1425.                         Get-PSDrive $_driveName | % { $_prefix + $_ + ':' }
  1426.                         break;
  1427.                     }
  1428.  
  1429.                     # Handle env&function drives variable name expansion...
  1430.                     '(^.*\$)(.*\:)(\w+)$' {
  1431.                         $_prefix = $matches[1]
  1432.                         $_drive = $matches[2]
  1433.                         $_varName = $matches[3]
  1434.                         if ($_drive -eq "env:" -or $_drive -eq "function:")
  1435.                         {
  1436.                             foreach ($_v in Get-ChildItem ($_drive + $_varName + '*'))
  1437.                             {
  1438.                                 $_prefix + $_drive + $_v.name
  1439.                             }
  1440.                         }
  1441.                         break;
  1442.                     }
  1443.  
  1444.                     # Handle array's element property and method expansion
  1445.                     # where there are intermediate properties...
  1446.                     # e.g. foo[0].n.b<tab>
  1447.                     '(^.*)(\$((\w+\.)|(\w+(\[(\w|,)+\])+\.))+)(\w*)$'
  1448.                     {
  1449.                         $_base = $matches[1]
  1450.                         $_expression = $matches[2].TrimEnd('.')
  1451.                         $_pat = $Matches[8] + '*'
  1452.                         [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1453.                         if ( $_expression -match '^\$_\.' )
  1454.                         {
  1455.                             $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1456.                         }
  1457.                         Write-Members
  1458.                         break;
  1459.                     }
  1460.  
  1461.                     # Handle property and method expansion rooted at type object...
  1462.                     # e.g. [System.Type].a<tab>
  1463.                     '(^\[(\w|\.)+\])\.(\w*)$'
  1464.                     {
  1465.                         if ( $(iex $Matches[1]) -isnot [System.Type] ) { break; }
  1466.                         $_expression = $Matches[1]
  1467.                         $_pat = $Matches[$matches.Count-1] + '*'
  1468.                         Write-Members
  1469.                         break;
  1470.                     }
  1471.  
  1472.                     # Handle complex property and method expansion on type object members
  1473.                     # where there are intermediate properties...
  1474.                     # e.g. [datetime].Assembly.a<tab>
  1475.                     '^(\[(\w|\.)+\]\.(\w+\.)+)(\w*)$' {
  1476.                         $_expression = $matches[1].TrimEnd('.') # expression less trailing '.'
  1477.                         $_pat = $matches[4] + '*'  # the member to look for...
  1478.                         if ( $(iex $_expression) -eq $null ) { break; }
  1479.                         Write-Members
  1480.                         break;
  1481.                     }
  1482.  
  1483.                     # Handle property and method expansion rooted at close parenthes...
  1484.                     # e.g. (123).a<tab>
  1485.                     '^(.*)\)((\w|\.)*)\.(\w*)$' {
  1486.                         $_base = $Matches[1] + ")"
  1487.                         if ( $matches[3] -eq $null) { $_expression = '[System.Type]' }
  1488.                         else { $_expression = '[System.Type]' + $Matches[2] }
  1489.                         $_pat = $matches[4] + '*'
  1490.                         iex "$_expression | Get-Member $_pat | sort MemberType,Name" |
  1491.                         % {
  1492.                             if ( $_.MemberType -like "*Method*" -or $_.MemberType -like "*Parameterized*" ) { $parenthes = "(" }
  1493.                             if ( $Matches[2] -eq "" ) { $_base + "." + $_.Name + $parenthes }
  1494.                             else { $_base + $Matches[2] + "." + $_.Name + $parenthes }
  1495.                           }
  1496.                         break;
  1497.                     }
  1498.  
  1499.                     # Handle .NET type name expansion ...
  1500.                     # e.g. [Microsoft.PowerShell.Com<tab>
  1501.                     '^((.*[=/;,\)}])?((\[(\w+(\.\w*)*)\])*))(\[(\w*(\.\w*)*))$' {
  1502.                         $_base = $matches[1]
  1503.                         $_opt = $matches[8] + '*'
  1504.                         if ( $_opt -eq "*" )
  1505.                         {
  1506.                             $_TypeAccelerators -replace '^(.*)$', '[$1]' | % { $_base + $_ }
  1507.                         }
  1508.                         else
  1509.                         {
  1510.                             $_TypeAccelerators -like $_opt -replace '^(.*)$', '[$1]' | % { $_base + $_ }
  1511.                             "CmdletBinding", "Parameter", "Alias",
  1512.                             "ValidateArguments", "ValidateCount", "ValidateEnumeratedArguments", "ValidateLength",
  1513.                             "ValidateNotNull", "ValidateNotNullOrEmpty", "ValidatePattern", "ValidateRange",
  1514.                             "ValidateScript", "ValidateSet", "AllowEmptyCollection", "AllowEmptyString", "AllowNull" `
  1515.                             -like $_opt -replace '^(.*)$', '[$1(' | % { $_base + $_ }
  1516.                             Write-ClassNames $_TypeNames_System ($_opt.Spli

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me