PoshCode Logo PowerShell Code Repository

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

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

  1. Now command name expansion’s priority is,

alias -> function -> filter -> cmdlet -> script -> external command

  1. Better type literal expansion with no spaces

[in<tab>[st<tab>[system<tab>

  1. Better expansion when the line include quortation mark

before echo “powershell”|te<tab> echo “powershell|tee”
after echo “powershell”|te<tab> echo “powershell”|tee

  1. PSDrive and item name expansion in variable notation
${fu<tab> ${function:cl<tab> ${c:<tab>\<tab> ${c:\win<tab>/sys<tab>/<tab>

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

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