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/978"></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 charactors
  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 charactor after Ctrl+X until the charactor
  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.  
  304. ### Generate ProgIDs list...
  305. if ( Test-Path $PSHOME\ProgIDs.txt )
  306. {
  307. $_ProgID = type $PSHOME\ProgIDs.txt -ReadCount 0
  308. }
  309. else
  310. {
  311. $_HKCR = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("CLSID\")
  312. $_ProgID = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  313. foreach ( $_subkey in $_HKCR.GetSubKeyNames() )
  314. {
  315. foreach ( $_i in [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey("CLSID\$_subkey\ProgID") )
  316. {
  317. if ($_i -ne $null)
  318. {
  319. $_ProgID.Add($_i.GetValue(""))
  320. }
  321. }
  322. }
  323. '$_ProgID was updated...' | Out-Host
  324. $_ProgID = $_ProgID|sort -Unique
  325.  
  326. Set-Content -Value $_ProgID -Path $PSHOME\ProgIDs.txt -Verbose
  327. }
  328.  
  329. ### Generate TypeNames list...
  330.  
  331. if ( Test-Path $PSHOME\TypeNames.txt )
  332. {
  333. $_TypeNames = type $PSHOME\TypeNames.txt -ReadCount 0
  334. }
  335. else
  336. {
  337. $_TypeNames = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  338. foreach ( $_asm in [AppDomain]::CurrentDomain.GetAssemblies() )
  339. {
  340. foreach ( $_type in $_asm.GetTypes() )
  341. {
  342. $_TypeNames.Add($_type.FullName)
  343. }
  344. }
  345. '$_TypeNames was updated...' | Out-Host
  346. $_TypeNames = $_TypeNames | sort -Unique
  347.  
  348. Set-Content -Value $_TypeNames -Path $PSHOME\TypeNames.txt -Verbose
  349. }
  350.  
  351. if ( Test-Path $PSHOME\TypeNames_System.txt )
  352. {
  353. $_TypeNames_System = type $PSHOME\TypeNames_System.txt -ReadCount 0
  354. }
  355. else
  356. {
  357. $_TypeNames_System = $_TypeNames -like "System.*" -replace '^System\.'
  358. '$_TypeNames_System was updated...' | Out-Host
  359. Set-Content -Value $_TypeNames_System -Path $PSHOME\TypeNames_System.txt -Verbose
  360. }
  361.  
  362. ### Generate WMIClasses list...
  363. if ( Test-Path $PSHOME\WMIClasses.txt )
  364. {
  365. $_WMIClasses = type $PSHOME\WMIClasses.txt -ReadCount 0
  366. }
  367. else
  368. {
  369. $_WMIClasses = New-Object ( [System.Collections.Generic.List``1].MakeGenericType([String]) )
  370. foreach ( $_class in gwmi -List )
  371. {
  372. $_WMIClasses.Add($_class.Name)
  373. }
  374. $_WMIClasses = $_WMIClasses | sort -Unique
  375. '$_WMIClasses was updated...' | Out-Host
  376. Set-Content -Value $_WMIClasses -Path $PSHOME\WMIClasses.txt -Verbose
  377. }
  378.  
  379. [Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms" ) | Out-Null
  380. $global:_cmdstack = New-Object Collections.Stack
  381. $global:_snapin = $null
  382. $global:_TypeAccelerators = [type]::gettype("System.Management.Automation.TypeAccelerators")::get.keys | sort
  383.  
  384. iex (@'
  385. function prompt {
  386. if ($_cmdstack.Count -gt 0) {
  387. $line = $global:_cmdstack.Pop() -replace '([[\]\(\)+{}?~%])','{$1}'
  388. [System.Windows.Forms.SendKeys]::SendWait($line)
  389. }
  390. '@ + @"
  391. ${function:prompt}
  392. }
  393. "@)
  394.  
  395. function Write-ClassNames ( $data, $i, $prefix='', $sep='.' )
  396. {
  397. $preItem = ""
  398. foreach ( $class in $data -like $_opt )
  399. {
  400. $Item = $class.Split($sep)
  401. if ( $preItem -ne $Item[$i] )
  402. {
  403. if ( $i+1 -eq $Item.Count )
  404. {
  405. if ( $prefix -eq "[" )
  406. {
  407. $suffix = "]"
  408. }
  409. elseif ( $sep -eq "_" )
  410. {
  411. $suffix = ""
  412. }
  413. else
  414. {
  415. $suffix = " "
  416. }
  417. }
  418. else
  419. {
  420. $suffix = ""
  421. }
  422. $prefix + $_opt.Substring(0, $_opt.LastIndexOf($sep)+1) + $Item[$i] + $suffix
  423.  
  424. $preItem = $Item[$i]
  425. }
  426. }
  427. }
  428.  
  429. function Get-PipeLineObject {
  430.  
  431. $i = -2
  432. $property = $null
  433. do {
  434. $str = $line.Split("|")
  435. # extract the command name from the string
  436. # first split the string into statements and pipeline elements
  437. # This doesn't handle strings however.
  438. $_cmdlet = [regex]::Split($str[$i], '[|;=]')[-1]
  439.  
  440. # take the first space separated token of the remaining string
  441. # as the command to look up. Trim any leading or trailing spaces
  442. # so you don't get leading empty elements.
  443. $_cmdlet = $_cmdlet.Trim().Split()[0]
  444.  
  445. if ( $_cmdlet -eq "?" )
  446. {
  447. $_cmdlet = "Where-Object"
  448. }
  449.  
  450. $global:_exp = $_cmdlet
  451.  
  452. # now get the info object for it...
  453. $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet)[0]
  454.  
  455. # loop resolving aliases...
  456. while ($_cmdlet.CommandType -eq 'alias')
  457. {
  458. $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet.Definition)[0]
  459. }
  460.  
  461. if ( "Select-Object" -eq $_cmdlet )
  462. {
  463. if ( $str[$i] -match '\s+-Exp\w*[\s:]+(\w+)' )
  464. {
  465. $property = $Matches[1] + ";" + $property
  466. }
  467. }
  468.  
  469. $i--
  470. } while ( "Get-Unique", "Select-Object", "Sort-Object", "Tee-Object", "Where-Object" -contains $_cmdlet )
  471.  
  472. if ( $global:_forgci -eq $null )
  473. {
  474. $a = @(ls "Alias:\")[0]
  475. $e = @(ls "Env:\")[0]
  476. $f = @(ls "Function:\")[0]
  477. $h = @(ls "HKCU:\")[0]
  478. $v = @(ls "Variable:\")[0]
  479. $c = @(ls "cert:\")[0]
  480. $global:_forgci = gi $PSHOME\powershell.exe |
  481. Add-Member  'NoteProperty'  CommandType  $f.CommandType -P |
  482. Add-Member  'NoteProperty'  Definition  $a.Definition -P |
  483. Add-Member  'NoteProperty'  Description  $a.Description -P |
  484. Add-Member  'NoteProperty'  Key  $e.Key -P |
  485. Add-Member  'NoteProperty'  Location  $c.Location -P |
  486. Add-Member  'NoteProperty'  LocationName  $c.LocationName -P |
  487. Add-Member  'NoteProperty'  Options  $a.Options -P |
  488. Add-Member  'NoteProperty'  ReferencedCommand  $a.ReferencedCommand -P |
  489. Add-Member  'NoteProperty'  ResolvedCommand  $a.ResolvedCommand -P |
  490. Add-Member  'NoteProperty'  ScriptBlock  $f.ScriptBlock -P |
  491. Add-Member  'NoteProperty'  StoreNames  $c.StoreNames -P |
  492. Add-Member  'NoteProperty'  SubKeyCount  $h.SubKeyCount -P |
  493. Add-Member  'NoteProperty'  Value  $e.Value -P |
  494. Add-Member  'NoteProperty'  ValueCount  $h.ValueCount -P |
  495. Add-Member  'NoteProperty'  Visibility  $a.Visibility -P |
  496. Add-Member  'NoteProperty'  Property  $h.Property -P |
  497. Add-Member  'NoteProperty'  ResolvedCommandName  $a.ResolvedCommandName -P |
  498. Add-Member  'ScriptMethod'  Close  {} -P |
  499. Add-Member  'ScriptMethod'  CreateSubKey  {} -P |
  500. Add-Member  'ScriptMethod'  DeleteSubKey  {} -P |
  501. Add-Member  'ScriptMethod'  DeleteSubKeyTree  {} -P |
  502. Add-Member  'ScriptMethod'  DeleteValue  {} -P |
  503. Add-Member  'ScriptMethod'  Flush  {} -P |
  504. Add-Member  'ScriptMethod'  GetSubKeyNames  {} -P |
  505. Add-Member  'ScriptMethod'  GetValue  {} -P |
  506. Add-Member  'ScriptMethod'  GetValueKind  {} -P |
  507. Add-Member  'ScriptMethod'  GetValueNames  {} -P |
  508. Add-Member  'ScriptMethod'  IsValidValue  {} -P |
  509. Add-Member  'ScriptMethod'  OpenSubKey  {} -P |
  510. Add-Member  'ScriptMethod'  SetValue  {} -P
  511. }
  512.  
  513. if ( $global:_mix -eq $null )
  514. {
  515. $f = gi $PSHOME\powershell.exe
  516. $t = [type]
  517. $s = ""
  518. $global:_mix = `
  519. Add-Member -InputObject (New-Object PSObject)  'NoteProperty'  Mode  $f.Mode -P |
  520. Add-Member  'NoteProperty'  Assembly  $t.Assembly -P |
  521. Add-Member  'NoteProperty'  AssemblyQualifiedName  $t.AssemblyQualifiedName -P |
  522. Add-Member  'NoteProperty'  Attributes  $f.Attributes -P |
  523. Add-Member  'NoteProperty'  BaseType  $t.BaseType -P |
  524. Add-Member  'NoteProperty'  ContainsGenericParameters  $t.ContainsGenericParameters -P |
  525. Add-Member  'NoteProperty'  CreationTime  $f.CreationTime -P |
  526. Add-Member  'NoteProperty'  CreationTimeUtc  $f.CreationTimeUtc -P |
  527. Add-Member  'NoteProperty'  DeclaringMethod  $t.DeclaringMethod -P |
  528. Add-Member  'NoteProperty'  DeclaringType  $t.DeclaringType -P |
  529. Add-Member  'NoteProperty'  Exists  $f.Exists -P |
  530. Add-Member  'NoteProperty'  Extension  $f.Extension -P |
  531. Add-Member  'NoteProperty'  FullName  $f.FullName -P |
  532. Add-Member  'NoteProperty'  GenericParameterAttributes  $t.GenericParameterAttributes -P |
  533. Add-Member  'NoteProperty'  GenericParameterPosition  $t.GenericParameterPosition -P |
  534. Add-Member  'NoteProperty'  GUID  $t.GUID -P |
  535. Add-Member  'NoteProperty'  HasElementType  $t.HasElementType -P |
  536. Add-Member  'NoteProperty'  IsAbstract  $t.IsAbstract -P |
  537. Add-Member  'NoteProperty'  IsAnsiClass  $t.IsAnsiClass -P |
  538. Add-Member  'NoteProperty'  IsArray  $t.IsArray -P |
  539. Add-Member  'NoteProperty'  IsAutoClass  $t.IsAutoClass -P |
  540. Add-Member  'NoteProperty'  IsAutoLayout  $t.IsAutoLayout -P |
  541. Add-Member  'NoteProperty'  IsByRef  $t.IsByRef -P |
  542. Add-Member  'NoteProperty'  IsClass  $t.IsClass -P |
  543. Add-Member  'NoteProperty'  IsCOMObject  $t.IsCOMObject -P |
  544. Add-Member  'NoteProperty'  IsContextful  $t.IsContextful -P |
  545. Add-Member  'NoteProperty'  IsEnum  $t.IsEnum -P |
  546. Add-Member  'NoteProperty'  IsExplicitLayout  $t.IsExplicitLayout -P |
  547. Add-Member  'NoteProperty'  IsGenericParameter  $t.IsGenericParameter -P |
  548. Add-Member  'NoteProperty'  IsGenericType  $t.IsGenericType -P |
  549. Add-Member  'NoteProperty'  IsGenericTypeDefinition  $t.IsGenericTypeDefinition -P |
  550. Add-Member  'NoteProperty'  IsImport  $t.IsImport -P |
  551. Add-Member  'NoteProperty'  IsInterface  $t.IsInterface -P |
  552. Add-Member  'NoteProperty'  IsLayoutSequential  $t.IsLayoutSequential -P |
  553. Add-Member  'NoteProperty'  IsMarshalByRef  $t.IsMarshalByRef -P |
  554. Add-Member  'NoteProperty'  IsNested  $t.IsNested -P |
  555. Add-Member  'NoteProperty'  IsNestedAssembly  $t.IsNestedAssembly -P |
  556. Add-Member  'NoteProperty'  IsNestedFamANDAssem  $t.IsNestedFamANDAssem -P |
  557. Add-Member  'NoteProperty'  IsNestedFamily  $t.IsNestedFamily -P |
  558. Add-Member  'NoteProperty'  IsNestedFamORAssem  $t.IsNestedFamORAssem -P |
  559. Add-Member  'NoteProperty'  IsNestedPrivate  $t.IsNestedPrivate -P |
  560. Add-Member  'NoteProperty'  IsNestedPublic  $t.IsNestedPublic -P |
  561. Add-Member  'NoteProperty'  IsNotPublic  $t.IsNotPublic -P |
  562. Add-Member  'NoteProperty'  IsPointer  $t.IsPointer -P |
  563. Add-Member  'NoteProperty'  IsPrimitive  $t.IsPrimitive -P |
  564. Add-Member  'NoteProperty'  IsPublic  $t.IsPublic -P |
  565. Add-Member  'NoteProperty'  IsSealed  $t.IsSealed -P |
  566. Add-Member  'NoteProperty'  IsSerializable  $t.IsSerializable -P |
  567. Add-Member  'NoteProperty'  IsSpecialName  $t.IsSpecialName -P |
  568. Add-Member  'NoteProperty'  IsUnicodeClass  $t.IsUnicodeClass -P |
  569. Add-Member  'NoteProperty'  IsValueType  $t.IsValueType -P |
  570. Add-Member  'NoteProperty'  IsVisible  $t.IsVisible -P |
  571. Add-Member  'NoteProperty'  LastAccessTime  $f.LastAccessTime -P |
  572. Add-Member  'NoteProperty'  LastAccessTimeUtc  $f.LastAccessTimeUtc -P |
  573. Add-Member  'NoteProperty'  LastWriteTime  $f.LastWriteTime -P |
  574. Add-Member  'NoteProperty'  LastWriteTimeUtc  $f.LastWriteTimeUtc -P |
  575. Add-Member  'NoteProperty'  MemberType  $t.MemberType -P |
  576. Add-Member  'NoteProperty'  MetadataToken  $t.MetadataToken -P |
  577. Add-Member  'NoteProperty'  Module  $t.Module -P |
  578. Add-Member  'NoteProperty'  Name  $t.Name -P |
  579. Add-Member  'NoteProperty'  Namespace  $t.Namespace -P |
  580. Add-Member  'NoteProperty'  Parent  $f.Parent -P |
  581. Add-Member  'NoteProperty'  ReflectedType  $t.ReflectedType -P |
  582. Add-Member  'NoteProperty'  Root  $f.Root -P |
  583. Add-Member  'NoteProperty'  StructLayoutAttribute  $t.StructLayoutAttribute -P |
  584. Add-Member  'NoteProperty'  TypeHandle  $t.TypeHandle -P |
  585. Add-Member  'NoteProperty'  TypeInitializer  $t.TypeInitializer -P |
  586. Add-Member  'NoteProperty'  UnderlyingSystemType  $t.UnderlyingSystemType -P |
  587. Add-Member  'NoteProperty'  PSChildName  $f.PSChildName -P |
  588. Add-Member  'NoteProperty'  PSDrive  $f.PSDrive -P |
  589. Add-Member  'NoteProperty'  PSIsContainer  $f.PSIsContainer -P |
  590. Add-Member  'NoteProperty'  PSParentPath  $f.PSParentPath -P |
  591. Add-Member  'NoteProperty'  PSPath  $f.PSPath -P |
  592. Add-Member  'NoteProperty'  PSProvider  $f.PSProvider -P |
  593. Add-Member  'NoteProperty'  BaseName  $f.BaseName -P |
  594. Add-Member  'ScriptMethod'  Clone  {} -P |
  595. Add-Member  'ScriptMethod'  CompareTo  {} -P |
  596. Add-Member  'ScriptMethod'  Contains  {} -P |
  597. Add-Member  'ScriptMethod'  CopyTo  {} -P |
  598. Add-Member  'ScriptMethod'  Create  {} -P |
  599. Add-Member  'ScriptMethod'  CreateObjRef  {} -P |
  600. Add-Member  'ScriptMethod'  CreateSubdirectory  {} -P |
  601. Add-Member  'ScriptMethod'  Delete  {} -P |
  602. Add-Member  'ScriptMethod'  EndsWith  {} -P |
  603. Add-Member  'ScriptMethod'  FindInterfaces  {} -P |
  604. Add-Member  'ScriptMethod'  FindMembers  {} -P |
  605. Add-Member  'ScriptMethod'  GetAccessControl  {} -P |
  606. Add-Member  'ScriptMethod'  GetArrayRank  {} -P |
  607. Add-Member  'ScriptMethod'  GetConstructor  {} -P |
  608. Add-Member  'ScriptMethod'  GetConstructors  {} -P |
  609. Add-Member  'ScriptMethod'  GetCustomAttributes  {} -P |
  610. Add-Member  'ScriptMethod'  GetDefaultMembers  {} -P |
  611. Add-Member  'ScriptMethod'  GetDirectories  {} -P |
  612. Add-Member  'ScriptMethod'  GetElementType  {} -P |
  613. Add-Member  'ScriptMethod'  GetEnumerator  {} -P |
  614. Add-Member  'ScriptMethod'  GetEvent  {} -P |
  615. Add-Member  'ScriptMethod'  GetEvents  {} -P |
  616. Add-Member  'ScriptMethod'  GetField  {} -P |
  617. Add-Member  'ScriptMethod'  GetFields  {} -P |
  618. Add-Member  'ScriptMethod'  GetFiles  {} -P |
  619. Add-Member  'ScriptMethod'  GetFileSystemInfos  {} -P |
  620. Add-Member  'ScriptMethod'  GetGenericArguments  {} -P |
  621. Add-Member  'ScriptMethod'  GetGenericParameterConstraints  {} -P |
  622. Add-Member  'ScriptMethod'  GetGenericTypeDefinition  {} -P |
  623. Add-Member  'ScriptMethod'  GetInterface  {} -P |
  624. Add-Member  'ScriptMethod'  GetInterfaceMap  {} -P |
  625. Add-Member  'ScriptMethod'  GetInterfaces  {} -P |
  626. Add-Member  'ScriptMethod'  GetLifetimeService  {} -P |
  627. Add-Member  'ScriptMethod'  GetMember  {} -P |
  628. Add-Member  'ScriptMethod'  GetMembers  {} -P |
  629. Add-Member  'ScriptMethod'  GetMethod  {} -P |
  630. Add-Member  'ScriptMethod'  GetMethods  {} -P |
  631. Add-Member  'ScriptMethod'  GetNestedType  {} -P |
  632. Add-Member  'ScriptMethod'  GetNestedTypes  {} -P |
  633. Add-Member  'ScriptMethod'  GetObjectData  {} -P |
  634. Add-Member  'ScriptMethod'  GetProperties  {} -P |
  635. Add-Member  'ScriptMethod'  GetProperty  {} -P |
  636. Add-Member  'ScriptMethod'  GetTypeCode  {} -P |
  637. Add-Member  'ScriptMethod'  IndexOf  {} -P |
  638. Add-Member  'ScriptMethod'  IndexOfAny  {} -P |
  639. Add-Member  'ScriptMethod'  InitializeLifetimeService  {} -P |
  640. Add-Member  'ScriptMethod'  Insert  {} -P |
  641. Add-Member  'ScriptMethod'  InvokeMember  {} -P |
  642. Add-Member  'ScriptMethod'  IsAssignableFrom  {} -P |
  643. Add-Member  'ScriptMethod'  IsDefined  {} -P |
  644. Add-Member  'ScriptMethod'  IsInstanceOfType  {} -P |
  645. Add-Member  'ScriptMethod'  IsNormalized  {} -P |
  646. Add-Member  'ScriptMethod'  IsSubclassOf  {} -P |
  647. Add-Member  'ScriptMethod'  LastIndexOf  {} -P |
  648. Add-Member  'ScriptMethod'  LastIndexOfAny  {} -P |
  649. Add-Member  'ScriptMethod'  MakeArrayType  {} -P |
  650. Add-Member  'ScriptMethod'  MakeByRefType  {} -P |
  651. Add-Member  'ScriptMethod'  MakeGenericType  {} -P |
  652. Add-Member  'ScriptMethod'  MakePointerType  {} -P |
  653. Add-Member  'ScriptMethod'  MoveTo  {} -P |
  654. Add-Member  'ScriptMethod'  Normalize  {} -P |
  655. Add-Member  'ScriptMethod'  PadLeft  {} -P |
  656. Add-Member  'ScriptMethod'  PadRight  {} -P |
  657. Add-Member  'ScriptMethod'  Refresh  {} -P |
  658. Add-Member  'ScriptMethod'  Remove  {} -P |
  659. Add-Member  'ScriptMethod'  Replace  {} -P |
  660. Add-Member  'ScriptMethod'  SetAccessControl  {} -P |
  661. Add-Member  'ScriptMethod'  Split  {} -P |
  662. Add-Member  'ScriptMethod'  StartsWith  {} -P |
  663. Add-Member  'ScriptMethod'  Substring  {} -P |
  664. Add-Member  'ScriptMethod'  ToCharArray  {} -P |
  665. Add-Member  'ScriptMethod'  ToLower  {} -P |
  666. Add-Member  'ScriptMethod'  ToLowerInvariant  {} -P |
  667. Add-Member  'ScriptMethod'  ToUpper  {} -P |
  668. Add-Member  'ScriptMethod'  ToUpperInvariant  {} -P |
  669. Add-Member  'ScriptMethod'  Trim  {} -P |
  670. Add-Member  'ScriptMethod'  TrimEnd  {} -P |
  671. Add-Member  'ScriptMethod'  TrimStart  {} -P |
  672. Add-Member  'NoteProperty'  Chars  $s.Chars -P
  673. }
  674.  
  675.  
  676. if ( "Add-Member" -eq $_cmdlet )
  677. {
  678. $global:_dummy = $null
  679. }
  680.  
  681.  
  682. if ( "Compare-Object" -eq $_cmdlet )
  683. {
  684. $global:_dummy =  (Compare-Object 1 2)[0]
  685. }
  686.  
  687.  
  688. if ( "ConvertFrom-SecureString" -eq $_cmdlet )
  689. {
  690. $global:_dummy = $null
  691. }
  692.  
  693.  
  694. if ( "ConvertTo-SecureString" -eq $_cmdlet )
  695. {
  696. $global:_dummy = convertto-securestring "P@ssW0rD!" -asplaintext -force
  697. }
  698.  
  699.  
  700. if ( "ForEach-Object" -eq $_cmdlet )
  701. {
  702. $global:_dummy = $null
  703. }
  704.  
  705.  
  706. if ( "Get-Acl" -eq $_cmdlet )
  707. {
  708. $global:_dummy = Get-Acl
  709. }
  710.  
  711.  
  712. if ( "Get-Alias" -eq $_cmdlet )
  713. {
  714. $global:_dummy = (Get-Alias)[0]
  715. }
  716.  
  717.  
  718. if ( "Get-AuthenticodeSignature" -eq $_cmdlet )
  719. {
  720. $global:_dummy = Get-AuthenticodeSignature $PSHOME\powershell.exe
  721. }
  722.  
  723.  
  724. if ( "Get-ChildItem" -eq $_cmdlet )
  725. {
  726. $global:_dummy = $global:_forgci
  727. }
  728.  
  729.  
  730. if ( "Get-Command" -eq $_cmdlet )
  731. {
  732. $global:_dummy = @(iex $str[$i+1])[0]
  733. }
  734.  
  735.  
  736. if ( "Get-Content" -eq $_cmdlet )
  737. {
  738. $global:_dummy = (type $PSHOME\profile.ps1)[0]
  739. }
  740.  
  741.  
  742. if ( "Get-Credential" -eq $_cmdlet )
  743. {
  744. $global:_dummy = $null
  745. }
  746.  
  747.  
  748. if ( "Get-Culture" -eq $_cmdlet )
  749. {
  750. $global:_dummy = Get-Culture
  751. }
  752.  
  753.  
  754. if ( "Get-Date" -eq $_cmdlet )
  755. {
  756. $global:_dummy = Get-Date
  757. }
  758.  
  759.  
  760. if ( "Get-Event" -eq $_cmdlet )
  761. {
  762. $global:_dummy = (Get-Event)[0]
  763. }
  764.  
  765.  
  766. if ( "Get-EventLog" -eq $_cmdlet )
  767. {
  768. $global:_dummy = @(iex $str[$i+1])[0]
  769. }
  770.  
  771.  
  772. if ( "Get-ExecutionPolicy" -eq $_cmdlet )
  773. {
  774. $global:_dummy = Get-ExecutionPolicy
  775. }
  776.  
  777.  
  778. if ( "Get-Help" -eq $_cmdlet )
  779. {
  780. $global:_dummy = Get-Help Add-Content
  781. }
  782.  
  783.  
  784. if ( "Get-History" -eq $_cmdlet )
  785. {
  786. $global:_dummy = Get-History -Count 1
  787. }
  788.  
  789.  
  790. if ( "Get-Host" -eq $_cmdlet )
  791. {
  792. $global:_dummy = Get-Host
  793. }
  794.  
  795.  
  796. if ( "Get-Item" -eq $_cmdlet )
  797. {
  798. $global:_dummy = $global:_forgci
  799. }
  800.  
  801.  
  802. if ( "Get-ItemProperty" -eq $_cmdlet )
  803. {
  804. $global:_dummy = $null
  805. }
  806.  
  807.  
  808. if ( "Get-Location" -eq $_cmdlet )
  809. {
  810. $global:_dummy = Get-Location
  811. }
  812.  
  813.  
  814. if ( "Get-Member" -eq $_cmdlet )
  815. {
  816. $global:_dummy = (1|Get-Member)[0]
  817. }
  818.  
  819.  
  820. if ( "Get-Module" -eq $_cmdlet )
  821. {
  822. $global:_dummy = (Get-Module)[0]
  823. }
  824.  
  825.  
  826. if ( "Get-PfxCertificate" -eq $_cmdlet )
  827. {
  828. $global:_dummy = $null
  829. }
  830.  
  831.  
  832. if ( "Get-Process" -eq $_cmdlet )
  833. {
  834. $global:_dummy = ps powershell
  835. }
  836.  
  837.  
  838. if ( "Get-PSBreakpoint" -eq $_cmdlet )
  839. {
  840. $global:_dummy =
  841. Add-Member -InputObject (New-Object PSObject)  'NoteProperty'  Action  '' -P |
  842. Add-Member  'NoteProperty'  Command  '' -P |
  843. Add-Member  'NoteProperty'  Enabled  '' -P |
  844. Add-Member  'NoteProperty'  HitCount  '' -P |
  845. Add-Member  'NoteProperty'  Id  '' -P |
  846. Add-Member  'NoteProperty'  Script  '' -P
  847. }
  848.  
  849.  
  850. if ( "Get-PSCallStack" -eq $_cmdlet )
  851. {
  852. $global:_dummy = Get-PSCallStack
  853. }
  854.  
  855.  
  856. if ( "Get-PSDrive" -eq $_cmdlet )
  857. {
  858. $global:_dummy = Get-PSDrive Function
  859. }
  860.  
  861.  
  862. if ( "Get-PSProvider" -eq $_cmdlet )
  863. {
  864. $global:_dummy = Get-PSProvider FileSystem
  865. }
  866.  
  867.  
  868. if ( "Get-PSSnapin" -eq $_cmdlet )
  869. {
  870. $global:_dummy = Get-PSSnapin Microsoft.PowerShell.Core
  871. }
  872.  
  873.  
  874. if ( "Get-Service" -eq $_cmdlet )
  875. {
  876. $global:_dummy = (Get-Service)[0]
  877. }
  878.  
  879.  
  880. if ( "Get-TraceSource" -eq $_cmdlet )
  881. {
  882. $global:_dummy = Get-TraceSource AddMember
  883. }
  884.  
  885.  
  886. if ( "Get-UICulture" -eq $_cmdlet )
  887. {
  888. $global:_dummy = Get-UICulture
  889. }
  890.  
  891.  
  892. if ( "Get-Variable" -eq $_cmdlet )
  893. {
  894. $global:_dummy = Get-Variable _
  895. }
  896.  
  897.  
  898. if ( "Get-WmiObject" -eq $_cmdlet )
  899. {
  900. $global:_dummy = @(iex $str[$i+1])[0]
  901. }
  902.  
  903.  
  904. if ( "Group-Object" -eq $_cmdlet )
  905. {
  906. $global:_dummy = 1 | group
  907. }
  908.  
  909.  
  910. if ( "Measure-Command" -eq $_cmdlet )
  911. {
  912. $global:_dummy = Measure-Command {}
  913. }
  914.  
  915.  
  916. if ( "Measure-Object" -eq $_cmdlet )
  917. {
  918. $global:_dummy = Measure-Object
  919. }
  920.  
  921.  
  922. if ( "New-PSDrive" -eq $_cmdlet )
  923. {
  924. $global:_dummy =  Get-PSDrive Alias
  925. }
  926.  
  927.  
  928. if ( "New-TimeSpan" -eq $_cmdlet )
  929. {
  930. $global:_dummy = New-TimeSpan
  931. }
  932.  
  933.  
  934. if ( "Resolve-Path" -eq $_cmdlet )
  935. {
  936. $global:_dummy = $PWD
  937. }
  938.  
  939.  
  940. if ( "Select-String" -eq $_cmdlet )
  941. {
  942. $global:_dummy = " " | Select-String " "
  943. }
  944.  
  945.  
  946. if ( "Set-Date" -eq $_cmdlet )
  947. {
  948. $global:_dummy =  Get-Date
  949. }
  950.  
  951. if ( $property -ne $null)
  952. {
  953. foreach ( $name in $property.Split(";", "RemoveEmptyEntries" -as [System.StringSplitOptions]) )
  954. {
  955. $global:_dummy = @($global:_dummy.$name)[0]
  956. }
  957. }
  958. }
  959.  
  960.  
  961. function TabExpansion {
  962. # This is the default function to use for tab expansion. It handles simple
  963. # member expansion on variables, variable name expansion and parameter completion
  964. # on commands. It doesn't understand strings so strings containing ; | ( or { may
  965. # cause expansion to fail.
  966.  
  967. param($line, $lastWord)
  968.  
  969. & {
  970. # Helper function to write out the matching set of members. It depends
  971. # on dynamic scoping to get $_base, _$expression and $_pat
  972. function Write-Members ($sep='.')
  973. {
  974. # evaluate the expression to get the object to examine...
  975. Invoke-Expression ('$_val=' + $_expression)
  976.  
  977. if ( $_expression -match '^\$global:_dummy' )
  978. {
  979. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  980. $_expression = '$_' + $temp
  981. }
  982.  
  983. $_method = [Management.Automation.PSMemberTypes] `
  984. 'Method,CodeMethod,ScriptMethod,ParameterizedProperty'
  985. if ($sep -eq '.')
  986. {
  987. $params = @{view = 'extended','adapted','base'}
  988. }
  989. else
  990. {
  991. $params = @{static=$true}
  992. }
  993.  
  994. if ( $_val -is [Hashtable] )
  995. {
  996. [Object[]]$_keys = $null
  997. foreach ( $_name in $_val.Keys )
  998. {
  999. $_keys += `
  1000. New-Object Microsoft.PowerShell.Commands.MemberDefinition `
  1001. [int],$_name,"Property",0
  1002. }
  1003. }
  1004.  
  1005. if ( $_keys -ne $null )
  1006. {
  1007. $_members = [Object[]](Get-Member @params -InputObject $_val $_pat) + ($_keys | ? {$_.name -like $_pat})
  1008. } else {
  1009. $_members = (Get-Member @params -InputObject $_val $_pat)
  1010. }
  1011.  
  1012. foreach ($_m in $_members | Sort-Object membertype,name)
  1013. {
  1014. if ($_m.MemberType -band $_method)
  1015. {
  1016. # Return a method...
  1017. $_base + $_expression + $sep + $_m.name + '('
  1018. }
  1019. else {
  1020. # Return a property...
  1021. $_base + $_expression + $sep + $_m.name
  1022. }
  1023. }
  1024. }
  1025.  
  1026. switch ([int]$line[-1])
  1027. {
  1028. # Ctrl+D several date/time formats
  1029. 4 {
  1030. "[DateTime]::Now"
  1031. [DateTime]::Now
  1032. [DateTime]::Now.ToString("yyyyMMdd")
  1033. [DateTime]::Now.ToString("MMddyyyy")
  1034. [DateTime]::Now.ToString("yyyyMMddHHmmss")
  1035. [DateTime]::Now.ToString("MMddyyyyHHmmss")
  1036. 'd f g m o r t u y'.Split(" ") | % { [DateTime]::Now.ToString($_) }
  1037. break;
  1038. }
  1039.  
  1040. # Ctrl+P hand-operated pop from command buffer stack
  1041. 16 {
  1042. $_base = $lastword.SubString(0, $lastword.Length-1)
  1043. $_base + $global:_cmdstack.Pop()
  1044. break;
  1045. }
  1046.  
  1047. # Ctrl+R $Host.UI.RawUI.
  1048. 18 {
  1049. '$Host.UI.RawUI.'
  1050. '$Host.UI.RawUI'
  1051. break;
  1052. }
  1053.  
  1054. # Ctrl+V paste clipboard
  1055. 22 {
  1056. $_base = $lastword.SubString(0, $lastword.Length-1)
  1057. $_clip = New-Object System.Windows.Forms.TextBox
  1058. $_clip.Multiline = $true
  1059. $_clip.Paste()
  1060. $_base + $_clip.Text
  1061. break;
  1062. }
  1063.  
  1064. # Ctrl+X cut current line
  1065. 24 {
  1066. $_clip = new-object System.Windows.Forms.TextBox;
  1067. $_clip.Multiline = $true;
  1068. $_clip.Text = $line.SubString(0, $line.Length-1)
  1069. $_clip.SelectAll()
  1070. $_clip.Copy()
  1071. [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1072. break;
  1073. }
  1074.  
  1075. # Ctrl+Z cut last word in current line
  1076. 26 {
  1077. $line.SubString(0, $line.Length-1) -match '(^(.*\s)([^\s]*)$)|(^[^\s]*$)' | Out-Null
  1078. $_clip = new-object System.Windows.Forms.TextBox;
  1079. $_clip.Multiline = $true;
  1080. $_clip.Text = $Matches[3]
  1081. $_clip.SelectAll()
  1082. $_clip.Copy()
  1083. [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1084. $line = $Matches[2] -replace '([[\]\(\)+{}?~%])','{$1}'
  1085. [System.Windows.Forms.SendKeys]::SendWait($line)
  1086. break;
  1087. }
  1088. }
  1089.  
  1090. switch ( [int]$line[-2] )
  1091. {
  1092. # Ctrl+X cut words with a charactor after Ctrl+X until the charactor
  1093. 24 {
  1094. $line.SubString(0, $line.Length-2) -match "(^(.*$($line[-1]))([^$($line[-1])]*)`$)|(^[^\$($line[-1])]*`$)" | Out-Null
  1095. $_clip = new-object System.Windows.Forms.TextBox;
  1096. $_clip.Multiline = $true;
  1097. $_clip.Text = $Matches[3]
  1098. $_clip.SelectAll()
  1099. $_clip.Copy()
  1100. [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1101. $line = $Matches[2] -replace '([[\]\(\)+{}?~%])','{$1}'
  1102. [System.Windows.Forms.SendKeys]::SendWait($line)
  1103. break;
  1104. }
  1105. }
  1106.  
  1107.  
  1108. switch -regex ($lastWord)
  1109. {
  1110. # Handle property and method expansion at '$_'
  1111. '(^.*)(\$_\.)(\w*)$' {
  1112. $_base = $matches[1]
  1113. $_expression = '$global:_dummy'
  1114. $_pat = $matches[3] + '*'
  1115. $global:_dummy = $null
  1116. Get-PipeLineObject
  1117. if ( $global:_dummy -eq $null )
  1118. {
  1119. if ( $global:_exp -match '^\$.*\(.*$' )
  1120. {
  1121. $type = ( iex $global:_exp.Split("(")[0] ).OverloadDefinitions[0].Split(" ")[0] -replace '\[[^\[\]]*\]$' -as [type]
  1122.  
  1123. if ( $_expression -match '^\$global:_dummy' )
  1124. {
  1125. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1126. $_expression = '$_' + $temp
  1127. }
  1128.  
  1129. foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1130. {
  1131. if ($_m.MemberType -eq "Method")
  1132. {
  1133. $_base + $_expression + '.' + $_m.name + '('
  1134. }
  1135. else {
  1136. $_base + $_expression + '.' + $_m.name
  1137. }
  1138. }
  1139. break;
  1140. }
  1141. elseif ( $global:_exp -match '^\[.*\:\:.*\(.*$' )
  1142. {
  1143. $tname, $mname = $_exp.Split(":(", "RemoveEmptyEntries"-as [System.StringSplitOptions])[0,1]
  1144. $type = @(iex ($tname + '.GetMember("' + $mname + '")'))[0].ReturnType.FullName -replace '\[[^\[\]]*\]$' -as [type]
  1145.  
  1146. if ( $_expression -match '^\$global:_dummy' )
  1147. {
  1148. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1149. $_expression = '$_' + $temp
  1150. }
  1151.  
  1152. foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1153. {
  1154. if ($_m.MemberType -eq "Method")
  1155. {
  1156. $_base + $_expression + '.' + $_m.name + '('
  1157. }
  1158. else {
  1159. $_base + $_expression + '.' + $_m.name
  1160. }
  1161. }
  1162. break;
  1163. }
  1164. elseif ( $global:_exp -match '^(\$\w+(\[[0-9,\.]+\])*(\.\w+(\[[0-9,\.]+\])*)*)$' )
  1165. {
  1166. $global:_dummy = @(iex $Matches[1])[0]
  1167. }
  1168. else
  1169. {
  1170. $global:_dummy =  $global:_mix
  1171. }
  1172. }
  1173.  
  1174. Write-Members
  1175. break;
  1176. }
  1177.  
  1178. # Handle property and method expansion rooted at variables...
  1179. # e.g. $a.b.<tab>
  1180. '(^.*)(\$(\w|\.)+)\.(\w*)$' {
  1181. $_base = $matches[1]
  1182. $_expression = $matches[2]
  1183. $_pat = $matches[4] + '*'
  1184. [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1185. if ( $_expression -match '^\$_\.' )
  1186. {
  1187. $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1188. }
  1189. Write-Members
  1190. break;
  1191. }
  1192.  
  1193. # Handle simple property and method expansion on static members...
  1194. # e.g. [datetime]::n<tab>
  1195. '(^.*)(\[(\w|\.)+\])\:\:(\w*)$' {
  1196. $_base = $matches[1]
  1197. $_expression = $matches[2]
  1198. $_pat = $matches[4] + '*'
  1199. Write-Members '::'
  1200. break;
  1201. }
  1202.  
  1203. # Handle complex property and method expansion on static members
  1204. # where there are intermediate properties...
  1205. # e.g. [datetime]::now.d<tab>
  1206. '(^.*)(\[(\w|\.)+\]\:\:(\w+\.)+)(\w*)$' {
  1207. $_base = $matches[1]  # everything before the expression
  1208. $_expression = $matches[2].TrimEnd('.') # expression less trailing '.'
  1209. $_pat = $matches[5] + '*'  # the member to look for...
  1210. Write-Members
  1211. break;
  1212. }
  1213.  
  1214. # Handle variable name expansion...
  1215. '(^.*\$)(\w+)$' {
  1216. $_prefix = $matches[1]
  1217. $_varName = $matches[2]
  1218. foreach ($_v in Get-ChildItem ('variable:' + $_varName + '*'))
  1219. {
  1220. $_prefix + $_v.name
  1221. }
  1222. break;
  1223. }
  1224.  
  1225. # Handle env&function drives variable name expansion...
  1226. '(^.*\$)(.*\:)(\w+)$' {
  1227. $_prefix = $matches[1]
  1228. $_drive = $matches[2]
  1229. $_varName = $matches[3]
  1230. if ($_drive -eq "env:" -or $_drive -eq "function:")
  1231. {
  1232. foreach ($_v in Get-ChildItem ($_drive + $_varName + '*'))
  1233. {
  1234. $_prefix + $_drive + $_v.name
  1235. }
  1236. }
  1237. break;
  1238. }
  1239.  
  1240. # Handle array's element property and method expansion
  1241. # where there are intermediate properties...
  1242. # e.g. foo[0].n.b<tab>
  1243. '(^.*)(\$((\w+\.)|(\w+(\[(\w|,)+\])+\.))+)(\w*)$'
  1244. {
  1245. $_base = $matches[1]
  1246. $_expression = $matches[2].TrimEnd('.')
  1247. $_pat = $Matches[8] + '*'
  1248. [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1249. if ( $_expression -match '^\$_\.' )
  1250. {
  1251. $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1252. }
  1253. Write-Members
  1254. break;
  1255. }
  1256.  
  1257. # Handle property and method expansion rooted at type object...
  1258. # e.g. [System.Type].a<tab>
  1259. '(^\[(\w|\.)+\])\.(\w*)$'
  1260. {
  1261. if ( $(iex $Matches[1]) -isnot [System.Type] ) { break; }
  1262. $_expression = $Matches[1]
  1263. $_pat = $Matches[$matches.Count-1] + '*'
  1264. Write-Members
  1265. break;
  1266. }
  1267.  
  1268. # Handle complex property and method expansion on type object members
  1269. # where there are intermediate properties...
  1270. # e.g. [datetime].Assembly.a<tab>
  1271. '^(\[(\w|\.)+\]\.(\w+\.)+)(\w*)$' {
  1272. $_expression = $matches[1].TrimEnd('.') # expression less trailing '.'
  1273. $_pat = $matches[4] + '*'  # the member to look for...
  1274. if ( $(iex $_expression) -eq $null ) { break; }
  1275. Write-Members
  1276. break;
  1277. }
  1278.  
  1279. # Handle property and method expansion rooted at close parenthes...
  1280. # e.g. (123).a<tab>
  1281. '^(.*)\)((\w|\.)*)\.(\w*)$' {
  1282. $_base = $Matches[1] + ")"
  1283. if ( $matches[3] -eq $null) { $_expression = '[System.Type]' }
  1284. else { $_expression = '[System.Type]' + $Matches[2] }
  1285. $_pat = $matches[4] + '*'
  1286. iex "$_expression | Get-Member $_pat | sort MemberType,Name" |
  1287. % {
  1288. if ( $_.MemberType -like "*Method*" -or $_.MemberType -like "*Parameterized*" ) { $parenthes = "(" }
  1289. if ( $Matches[2] -eq "" ) { $_base + "." + $_.Name + $parenthes }
  1290. else { $_base + $Matches[2] + "." + $_.Name + $parenthes }
  1291. }
  1292. break;
  1293. }
  1294.  
  1295. # Handle .NET type name expansion ...
  1296. # e.g. [Microsoft.PowerShell.Com<tab>
  1297. '^\[(\w+(\.\w*)*)$' {
  1298. $_opt = $matches[1] + '*'
  1299. if ( $_opt -eq "*" )
  1300. {
  1301. $_TypeAccelerators -like $_opt -replace '^(.*)$', '[$1]'
  1302. }
  1303. else
  1304. {
  1305. $_TypeAccelerators -like $_opt -replace '^(.*)$', '[$1]'
  1306. "CmdletBinding", "Parameter", "Alias",
  1307. "ValidateArguments", "ValidateCount", "ValidateEnumeratedArguments", "ValidateLength",
  1308. "ValidateNotNull", "ValidateNotNullOrEmpty", "ValidatePattern", "ValidateRange",
  1309. "ValidateScript", "ValidateSet", "AllowEmptyCollection", "AllowEmptyString", "AllowNull" `
  1310. -like $_opt -replace '^(.*)$', '[$1('
  1311. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1) '['
  1312. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1) '['
  1313. }
  1314. break;
  1315. }
  1316.  
  1317. # Handle file/directory name which contains $env: variable
  1318. # e.g.  $env:windir\<tab>
  1319. '^\$(env:)?\w+([\\/][^\\/]*)*$' {
  1320. $path = iex ('"' + $Matches[0] + '"')
  1321. if ( $Matches[2].Length -gt 1 )
  1322. {
  1323. $parent = Split-Path $path -Parent
  1324. $leaf = (Split-Path $path -Leaf) + '*'
  1325. }
  1326. else
  1327. {
  1328. $parent = $path
  1329. $leaf = '*'
  1330. }
  1331. if ( Test-Path $parent )
  1332. {
  1333. $i = $Matches[0].LastIndexOfAny("/\")
  1334. $_base = $Matches[0].Substring(0,$i+1)
  1335. [IO.Directory]::GetFileSystemEntries( $parent, $leaf ) | % { $_base + ($_.Split("\/")[-1] -replace '([\$\s&])','`$1' -replace '([[\]])', '````$1') }
  1336. }
  1337. }
  1338.  
  1339. # Handle file glob expansion ...
  1340. # e.g. *.txt~about*@<tab>
  1341. '^(\^?([^~]+))(~(.*))*@$' {
  1342. if ( $Matches[1] -notlike "^*" )
  1343. {
  1344. $include = $Matches[2] -replace '``','`'
  1345. if ( $Matches[3] )
  1346. {
  1347. $exclude = $Matches[3].Split("~", "RemoveEmptyEntries" -as [System.StringSplitOptions]) -replace '``','`'
  1348. }
  1349. }
  1350. else
  1351. {
  1352. $include = "*"
  1353. $exclude = $Matches[2] -replace '``','`'
  1354. }
  1355. $fse = [IO.Directory]::GetFileSystemEntries($PWD)
  1356. $fse = $fse -replace '.*[\\/]([^/\\]*)$','$1'
  1357. % -in ($fse -like $include) { $fse = $_; $exclude | % { $fse = $fse -notlike $_ } }
  1358. $fse = $fse -replace '^.*\s.*$', ("'`$0'")
  1359. $fse = $fse -replace '([\[\]])', '``$1' -replace '^.*([\[\]]).*$', ("'`$0'")
  1360. $fse = $fse -replace "''", "'"
  1361. $OFS = ", "; "$fse"
  1362. $OFS = ", "; "* -Filter $include " + $(if($exclude){"-Exclude $exclude"})
  1363. $Matches[0].Substring(0, $Matches[0].Length-1)
  1364. break;
  1365. }
  1366.  
  1367. # Handle command buffer stack...
  1368. '(.*);(.?)$' {
  1369. $_base = $Matches[1]
  1370. if ( $Matches[2] -eq ":" -or $Matches[2] -eq "," )
  1371. {
  1372. if ( $_cmdstack.Count -gt 0 )
  1373. {
  1374. $_base + $global:_cmdstack.Pop()
  1375. }
  1376. else
  1377. {
  1378. ""; break;
  1379. }
  1380. }
  1381. elseif ( $Matches[2] -eq "" )
  1382. {
  1383. $global:_cmdstack.Push($line.SubString(0,$line.Length-1))
  1384. [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1385. ""; break;
  1386. }
  1387. }
  1388.  
  1389. # Do completion on parameters...
  1390. '^-([\w0-9]*)' {
  1391. $_pat = $matches[1] + '*'
  1392.  
  1393. # extract the command name from the string
  1394. # first split the string into statements and pipeline elements
  1395. # This doesn't handle strings however.
  1396. $_command = [regex]::Split($line, '[|;=]')[-1]
  1397.  
  1398. #  Extract the trailing unclosed block e.g. ls | foreach { cp
  1399. if ($_command -match '\{([^\{\}]*)$')
  1400. {
  1401. $_command = $matches[1]
  1402. }
  1403.  
  1404. # Extract the longest unclosed parenthetical expression...
  1405. if ($_command -match '\(([^()]*)$')
  1406. {
  1407. $_command = $matches[1]
  1408. }
  1409.  
  1410. # take the first space separated token of the remaining string
  1411. # as the command to look up. Trim any leading or trailing spaces
  1412. # so you don't get leading empty elements.
  1413. $_command = $_command.Trim().Split()[0]
  1414.  
  1415. # now get the info object for it...
  1416. $_command = @(Get-Command -type 'All' $_command)[0]
  1417.  
  1418. # loop resolving aliases...
  1419. while ($_command.CommandType -eq 'alias')
  1420. {
  1421. $_command = @(Get-Command -type 'All' $_command.Definition)[0]
  1422. }
  1423.  
  1424. if ( $_command.name -eq "powershell.exe" )
  1425. {
  1426. if ( $global:_PSexeOption )
  1427. {
  1428. $global:_PSexeOption -like "-$_pat" -replace '^(-[^,]+).*$', '$1' | sort
  1429. }
  1430. else
  1431. {
  1432. ($global:_PSexeOption = powershell.exe -?) -like "-$_pat" -replace '^(-[^,]+).*$', '$1' | sort
  1433. }
  1434. break;
  1435. }
  1436.  
  1437.  
  1438. if ( $_command -ne $null )
  1439. {
  1440. # expand the parameter sets and emit the matching elements
  1441. foreach ($_n in $_command.Parameters.Keys | sort)
  1442. {
  1443. if ($_n -like $_pat) { '-' + $_n }
  1444. }
  1445. }
  1446. elseif ( $line -match 'switch\s+(-\w+\s+)*-(\w*)$')
  1447. {
  1448. $_pat = $Matches[2] + '*'
  1449. "regex", "wildcard", "exact", "casesensitive", "file" -like $_pat -replace '^(.*)$', '-$1'
  1450. break;
  1451. }
  1452. else
  1453. {
  1454. "-and", "-as", "-band", "-bnot", "-bor", "-bxor", "-ccontains", "-ceq", "-cge", "-cgt", "-cle", "-clike", "-clt",
  1455. "-cmatch", "-cne", "-cnotcontains", "-cnotlike", "-cnotmatch", "-contains", "-creplace", "-csplit", "-eq", "-f", "-ge",
  1456. "-gt", "-icontains", "-ieq", "-ige", "-igt", "-ile", "-ilike", "-ilt", "-imatch", "-ine", "-inotcontains", "-inotlike",
  1457. "-inotmatch", "-ireplace", "-is", "-isnot", "-isplit", "-join", "-le", "-like", "-lt", "-match", "-ne", "-not", "-notcontains",
  1458. "-notlike", "-notmatch", "-or", "-replace", "-split", "-xor" -like "-$_pat"
  1459. }
  1460. break;
  1461. }
  1462.  
  1463. # Tab complete against history either #<pattern> or #<id>
  1464. '^#(\w*)' {
  1465. $_pattern = $matches[1]
  1466. if ($_pattern -match '^[0-9]+$')
  1467. {
  1468. Get-History -ea SilentlyContinue -Id $_pattern | Foreach { $_.CommandLine }
  1469. }
  1470. else
  1471. {
  1472. $_pattern = '*' + $_pattern + '*'
  1473. Get-History | Sort-Object -Descending Id| Foreach { $_.CommandLine } | where { $_ -like $_pattern }
  1474. }
  1475. break;
  1476. }
  1477.  
  1478. # try to find a matching command...
  1479. default {
  1480.  
  1481. # parse the script...
  1482. $_tokens = [System.Management.Automation.PSParser]::Tokenize($line, [ref] $null)
  1483.  
  1484. if ( $_tokens )
  1485. {
  1486. $_lastToken = $_tokens[$_tokens.count - 1]
  1487. if ($_lastToken.Type -eq 'Member')
  1488. {
  1489. $_pat = $_lastToken.Content + '*'
  1490. $i=$_tokens.count; do { $i-- } until ( $_tokens[$i].Type -eq "Attribute")
  1491. if ( $lastWord -match "^(.*)([\(,])\w*$" )
  1492. {
  1493. $_base = $matches[1] + $matches[2]
  1494. }
  1495. switch ( $_tokens[$i].Content )
  1496. {
  1497. 'Parameter' {
  1498. [System.Management.Automation.ParameterAttribute].GetProperties() | ? { $_.Name -like $_pat -and $_.Name -ne "TypeId" } | % { $_base + $_.Name + "=" }
  1499. }
  1500. 'CmdletBinding' {
  1501. [System.Management.Automation.CmdletBindingAttribute].GetProperties() | ? { $_.Name -like $_pat -and $_.Name -ne "TypeId" } | % { $_base + $_.Name + "=" }
  1502. }
  1503. }
  1504. break;
  1505. }
  1506.  
  1507. if ( $_tokens[1].Type -eq "Attribute")
  1508. {
  1509. if ( $line.Split("(").Count -gt $line.Split(")").Count )
  1510. {
  1511. if ( $lastWord -match "^(.*)([\(,])\w*$" )
  1512. {
  1513. $_base = $matches[1] + $matches[2]
  1514. }
  1515. switch ( $_tokens[1].Content )
  1516. {
  1517. 'Parameter' {
  1518. [System.Management.Automation.ParameterAttribute].GetProperties() | % { $_base + $_.Name + "=" }
  1519. }
  1520. 'CmdletBinding' {
  1521. [System.Management.Automation.CmdletBindingAttribute].GetProperties()  | % { $_base + $_.Name + "=" }
  1522. }
  1523. }
  1524. }
  1525. break;
  1526. }
  1527. }
  1528.  
  1529.  
  1530. $lastex =  [regex]::Split($line, '[|;]')[-1]
  1531. if ( $lastex -match '^\s*(\$\w+(\[[0-9,]+\])*(\.\w+(\[[0-9,]+\])*)*)\s*=\s+(("\w+"\s*,\s+)*)"\w+"\s*-as\s+$' )
  1532. {
  1533. if ( $Matches[6] -ne $nul )
  1534. {
  1535. $brackets = "[]"
  1536. }
  1537. '['+ $global:_enum + $brackets + ']'
  1538. break;
  1539. }
  1540.  
  1541.  
  1542. if ( $lastex -match '^\s*(\$\w+(\[[0-9,]+\])*(\.\w+(\[[0-9,]+\])*)*)\s*=\s+(("\w+"\s*,\s+)*)\s*(\w*)$' )
  1543. {
  1544. $_pat = $Matches[7] + '*'
  1545.  
  1546. $_type = @(iex $Matches[1])[0].GetType()
  1547. if ( $_type.IsEnum )
  1548. {
  1549. $global:_enum = $_type.FullName
  1550. [Enum]::GetValues($_type) -like $_pat -replace '^(.*)$','"$1"'
  1551. break;
  1552. }
  1553. }
  1554.  
  1555. $lastex =  [regex]::Split($line, '[|;=]')[-1]
  1556. if ($lastex  -match '[[$].*\w+\(.*-as\s*$')
  1557. {
  1558. '['+ $global:_enum + ']'
  1559. }
  1560. elseif ( $lastex -match '([[$].*(\w+))\((.*)$' )
  1561. {
  1562. $_method = $Matches[1]
  1563.  
  1564. if ( $Matches[3] -match "(.*)((`"|')(\w+,)+(\w*))$" )
  1565. {
  1566. $continuous = $true
  1567. $_opt =  $Matches[5] + '*'
  1568. $_base =  $Matches[2].TrimStart('"') -replace '(.*,)\w+$','$1'
  1569. $position = $Matches[1].Split(",").Length
  1570. }
  1571. else
  1572. {
  1573. $continuous = $false
  1574. $_opt = ($Matches[3].Split(',')[-1] -replace '^\s*','') + "*"
  1575. $position = $Matches[3].Split(",").Length
  1576. }
  1577.  
  1578. if ( ($_mdefs = iex ($_method + ".OverloadDefinitions")) -eq $null )
  1579. {
  1580. $tname, $mname = $_method.Split(":", "RemoveEmptyEntries" -as [System.StringSplitOptions])
  1581. $_mdefs = iex ($tname + '.GetMember("' + $mname + '") | % { $_.ToString() }')
  1582. }
  1583.  
  1584. foreach ( $def in $_mdefs )
  1585. {
  1586. [void] ($def -match '\((.*)\)')
  1587. foreach ( $param in [regex]::Split($Matches[1], ', ')[$position-1] )
  1588. {
  1589. if ($param -eq $null -or $param -eq "")
  1590. {
  1591. continue;
  1592. }
  1593. $type = $param.split()[0]
  1594.  
  1595. if ( $type -like '*`[*' -or $type -eq "Params" -or $type -eq "" )
  1596. {
  1597. continue;
  1598. }
  1599. $fullname  = @($_typenames -like "*$type*")
  1600. foreach ( $name in $fullname )
  1601. {
  1602. if ( $continuous -eq $true -and ( $name  -as [System.Type] ).IsEnum )
  1603. {
  1604. $output = [Enum]::GetValues($name) -like $_opt -replace '^(.*)$',($_base + '$1')
  1605. $output | sort
  1606. }
  1607. elseif ( ( $name  -as [System.Type] ).IsEnum )
  1608. {
  1609. $global:_enum = $name
  1610. $output = [Enum]::GetValues($name) -like $_opt -replace '^(.*)$','"$1"'
  1611. $output | sort
  1612. }
  1613. }
  1614. }
  1615. }
  1616. if ( $output -ne $null )
  1617. {
  1618. break;
  1619. }
  1620. }
  1621.  
  1622. if ( $line -match '(function|filter)\s+(\w*)$')
  1623. {
  1624. $_pat = 'function:\' + $Matches[2] + '*'
  1625. Get-ChildItem $_pat| % { $_.Name }
  1626. break;
  1627. }
  1628.  
  1629.  
  1630. if ( $line[-1] -eq " " )
  1631. {
  1632. $_cmdlet = $line.TrimEnd(" ").Split(" |(;={")[-1]
  1633.  
  1634. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet)[0]
  1635.  
  1636. while ($_cmdlet.CommandType -eq 'alias')
  1637. {
  1638. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet.Definition)[0]
  1639. }
  1640.  
  1641. if ( "Set-ExecutionPolicy" -eq $_cmdlet.Name )
  1642. {
  1643. "Unrestricted", "RemoteSigned", "AllSigned", "Restricted", "Default" | sort
  1644. break;
  1645. }
  1646.  
  1647. if ( "Trace-Command","Get-TraceSource","Set-TraceSource" -contains $_cmdlet.Name )
  1648. {
  1649. Get-TraceSource | % { $_.Name } | sort -Unique
  1650. break;
  1651. }
  1652.  
  1653. if ( "New-Object" -eq $_cmdlet.Name )
  1654. {
  1655. $_TypeAccelerators
  1656. break;
  1657. }
  1658.  
  1659. if ( $_cmdlet.Noun -like "*WMI*" )
  1660. {
  1661. $_WMIClasses
  1662. break;
  1663. }
  1664.  
  1665. if ( "Get-Process" -eq $_cmdlet.Name )
  1666. {
  1667. Get-Process | % { $_.Name } | sort
  1668. break;
  1669. }
  1670.  
  1671. if ( "Add-PSSnapin", "Get-PSSnapin", "Remove-PSSnapin" -contains $_cmdlet.Name )
  1672. {
  1673. if ( $global:_snapin -ne $null )
  1674. {
  1675. $global:_snapin
  1676. break;
  1677. }
  1678. else
  1679. {
  1680. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  1681. $global:_snapin
  1682. break;
  1683. }
  1684. }
  1685.  
  1686. if ( "Get-PSDrive", "New-PSDrive", "Remove-PSDrive" `
  1687. -contains $_cmdlet.Name -and "Name" )
  1688. {
  1689. Get-PSDrive | sort
  1690. break;
  1691. }
  1692.  
  1693. if ( "Get-Eventlog" -eq $_cmdlet.Name )
  1694. {
  1695. Get-EventLog -List | % { $_base + ($_.Log -replace '\s','` ') }
  1696. break;
  1697. }
  1698.  
  1699. if ( "Get-Help" -eq $_cmdlet.Name -or "help" -eq $_cmdlet.Name )
  1700. {
  1701. Get-Help -Category all | % { $_.Name } | sort -Unique
  1702. break;
  1703. }
  1704.  
  1705. if ( "Get-Service", "Restart-Service", "Resume-Service",
  1706. "Start-Service", "Stop-Service", "Suspend-Service" `
  1707. -contains $_cmdlet.Name )
  1708. {
  1709. Get-Service | sort Name  | % { $_base + ($_.Name -replace '\s','` ') }
  1710. break;
  1711. }
  1712.  
  1713. if ( "Get-Command" -eq $_cmdlet.Name )
  1714. {
  1715. Get-Command -CommandType All | % { $_base + ($_.Name -replace '\s','` ') }
  1716. break;
  1717. }
  1718.  
  1719. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Compare-Object",
  1720. "ConvertTo-Html", "Measure-Object", "Select-Object", "Group-Object", "Sort-Object" `
  1721. -contains $_cmdlet.Name )
  1722. {
  1723. Get-PipeLineObject
  1724. $_dummy | gm -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  1725. break;
  1726. }
  1727.  
  1728. if ( "Clear-Variable", "Get-Variable", "New-Variable", "Remove-Variable", "Set-Variable" -contains $_cmdlet.Name )
  1729. {
  1730. Get-Variable -Scope Global | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1731. break;
  1732. }
  1733.  
  1734. if ( "Get-Alias", "New-Alias", "Set-Alias" -contains $_cmdlet.Name )
  1735. {
  1736. Get-Alias | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1737. break;
  1738. }
  1739. }
  1740.  
  1741.  
  1742. if ( $line[-1] -eq " " )
  1743. {
  1744. $_cmdlet = [regex]::Split($line, '[|;=]')[-1]
  1745.  
  1746. if ($_cmdlet -match '\{([^\{\}]*)$')
  1747. {
  1748. $_cmdlet = $matches[1]
  1749. }
  1750.  
  1751. if ($_cmdlet -match '\(([^()]*)$')
  1752. {
  1753. $_cmdlet = $matches[1]
  1754. }
  1755.  
  1756. $_cmdlet = $_cmdlet.Trim().Split()[0]
  1757.  
  1758. $_cmdlet = @(Get-Command -type 'Application' $_cmdlet)[0]
  1759.  
  1760. if ( $_cmdlet.Name -eq "powershell.exe" )
  1761. {
  1762. "-PSConsoleFile", "-Version", "-NoLogo", "-NoExit", "-Sta", "-NoProfile", "-NonInteractive",
  1763. "-InputFormat", "-OutputFormat", "-EncodedCommand", "-File", "-Command" | sort
  1764. break;
  1765. }
  1766. if ( $_cmdlet.Name -eq "fsutil.exe" )
  1767. {
  1768. "behavior query", "behavior set", "dirty query", "dirty set",
  1769. "file findbysid", "file queryallocranges", "file setshortname", "file setvaliddata", "file setzerodata", "file createnew",
  1770. "fsinfo drives", "fsinfo drivetype", "fsinfo volumeinfo", "fsinfo ntfsinfo", "fsinfo statistics",
  1771. "hardlink create", "objectid query", "objectid set", "objectid delete", "objectid create",
  1772. "quota disable", "quota track", "quota enforce", "quota violations", "quota modify", "quota query",
  1773. "reparsepoint query", "reparsepoint delete", "sparse setflag", "sparse queryflag", "sparse queryrange", "sparse setrange",
  1774. "usn createjournal", "usn deletejournal", "usn enumdata", "usn queryjournal", "usn readdata", "volume dismount", "volume diskfree" | sort
  1775. break;
  1776. }
  1777. if ( $_cmdlet.Name -eq "net.exe" )
  1778. {
  1779. "ACCOUNTS ", " COMPUTER ", " CONFIG ", " CONTINUE ", " FILE ", " GROUP ", " HELP ",
  1780. "HELPMSG ", " LOCALGROUP ", " NAME ", " PAUSE ", " PRINT ", " SEND ", " SESSION ",
  1781. "SHARE ", " START ", " STATISTICS ", " STOP ", " TIME ", " USE ", " USER ", " VIEW" | sort
  1782. break;
  1783. }
  1784. if ( $_cmdlet.Name -eq "ipconfig.exe" )
  1785. {
  1786. "/?", "/all", "/renew", "/release", "/flushdns", "/displaydns",
  1787. "/registerdns", "/showclassid", "/setclassid"
  1788. break;
  1789. }
  1790. }
  1791.  
  1792. if ( $line -match '\w+\s+(\w+(\.|[^\s\.])*)$' )
  1793. {
  1794. $_cmdlet = $line.TrimEnd(" ").Split(" |(;={")[-2]
  1795.  
  1796. $_opt = $Matches[1].Split(" ,")[-1] + '*'
  1797. $_base = $Matches[1].Substring(0,$Matches[1].Length-$Matches[1].Split(" ,")[-1].length)
  1798.  
  1799. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet)[0]
  1800.  
  1801. while ($_cmdlet.CommandType -eq 'alias')
  1802. {
  1803. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet.Definition)[0]
  1804. }
  1805.  
  1806. if ( "Set-ExecutionPolicy" -eq $_cmdlet.Name )
  1807. {
  1808. "Unrestricted", "RemoteSigned", "AllSigned", "Restricted", "Default" -like $_opt | sort
  1809. break;
  1810. }
  1811.  
  1812. if ( "Trace-Command","Get-TraceSource","Set-TraceSource" -contains $_cmdlet.Name )
  1813. {
  1814. Get-TraceSource -Name $_opt | % { $_.Name } | sort -Unique | % { $_base + ($_ -replace '\s','` ') }
  1815. break;
  1816. }
  1817.  
  1818. if ( "New-Object" -eq $_cmdlet.Name )
  1819. {
  1820. $_TypeAccelerators -like $_opt
  1821. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1)
  1822. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1)
  1823. break;
  1824. }
  1825.  
  1826. if ( $_cmdlet.Name -like "*WMI*" )
  1827. {
  1828. Write-ClassNames $_WMIClasses ($_opt.Split("_").Count-1) -sep '_'
  1829. break;
  1830. }
  1831.  
  1832. if ( "Get-Process" -eq $_cmdlet.Name )
  1833. {
  1834. Get-Process $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1835. break;
  1836. }
  1837.  
  1838. if ( "Add-PSSnapin", "Get-PSSnapin", "Remove-PSSnapin" -contains $_cmdlet.Name )
  1839. {
  1840. if ( $global:_snapin -ne $null )
  1841. {
  1842. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  1843. break;
  1844. }
  1845. else
  1846. {
  1847. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  1848. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  1849. break;
  1850. }
  1851. }
  1852.  
  1853. if ( "Get-PSDrive", "New-PSDrive", "Remove-PSDrive" `
  1854. -contains $_cmdlet.Name -and "Name" )
  1855. {
  1856. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  1857. break;
  1858. }
  1859.  
  1860. if ( "Get-PSProvider" -eq $_cmdlet.Name )
  1861. {
  1862. Get-PSProvider -PSProvider $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1863. break;
  1864. }
  1865.  
  1866.  
  1867. if ( "Get-Eventlog" -eq $_cmdlet.Name )
  1868. {
  1869. Get-EventLog -List | ? { $_.Log -like $_opt } | % { $_base + ($_.Log -replace '\s','` ') }
  1870. break;
  1871. }
  1872.  
  1873. if ( "Get-Help" -eq $_cmdlet.Name -or "help" -eq $_cmdlet.Name )
  1874. {
  1875. Get-Help -Category all -Name $_opt | % { $_.Name } | sort -Unique
  1876. break;
  1877. }
  1878.  
  1879. if ( "Get-Service", "Restart-Service", "Resume-Service",
  1880. "Start-Service", "Stop-Service", "Suspend-Service" `
  1881. -contains $_cmdlet.Name )
  1882. {
  1883. Get-Service -Name $_opt | sort Name  | % { $_base + ($_.Name -replace '\s','` ') }
  1884. break;
  1885. }
  1886.  
  1887. if ( "Get-Command" -eq $_cmdlet.Name )
  1888. {
  1889. Get-Command -CommandType All -Name $_opt | % { $_base + ($_.Name -replace '\s','` ') }
  1890. break;
  1891. }
  1892.  
  1893. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Compare-Object",
  1894. "ConvertTo-Html", "Measure-Object", "Select-Object", "Group-Object", "Sort-Object" `
  1895. -contains $_cmdlet.Name )
  1896. {
  1897.  
  1898. Get-PipeLineObject
  1899. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  1900. break;
  1901. }
  1902.  
  1903. if ( "Clear-Variable", "Get-Variable", "New-Variable", "Remove-Variable", "Set-Variable" -contains $_cmdlet.Name )
  1904. {
  1905. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1906. break;
  1907. }
  1908.  
  1909. if ( "Get-Alias", "New-Alias", "Set-Alias" -contains $_cmdlet.Name )
  1910. {
  1911. Get-Alias -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1912. break;
  1913. }
  1914. }
  1915.  
  1916. if ( $line -match '(-(\w+))\s+([^-]*$)' )
  1917. {
  1918.  
  1919. $_param = $matches[2] + '*'
  1920. $_opt = $Matches[3].Split(" ,")[-1] + '*'
  1921. $_base = $Matches[3].Substring(0,$Matches[3].Length-$Matches[3].Split(" ,")[-1].length)
  1922.  
  1923. $_cmdlet = [regex]::Split($line, '[|;=]')[-1]
  1924.  
  1925. if ($_cmdlet -match '\{([^\{\}]*)$')
  1926. {
  1927. $_cmdlet = $matches[1]
  1928. }
  1929.  
  1930. if ($_cmdlet -match '\(([^()]*)$')
  1931. {
  1932. $_cmdlet = $matches[1]
  1933. }
  1934.  
  1935. $_cmdlet = $_cmdlet.Trim().Split()[0]
  1936.  
  1937. $_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet)[0]
  1938.  
  1939. while ($_cmdlet.CommandType -eq 'alias')
  1940. {
  1941. $_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet.Definition)[0]
  1942. }
  1943.  
  1944. if ( $_param.TrimEnd("*") -eq "ea" -or $_param.TrimEnd("*") -eq "wa" )
  1945. {
  1946. "SilentlyContinue", "Stop", "Continue", "Inquire" |
  1947. ? { $_ -like $_opt } | sort -Unique
  1948. break;
  1949. }
  1950.  
  1951. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide" -contains $_cmdlet.Name `
  1952. -and "groupBy" -like $_param )
  1953. {
  1954. Get-PipeLineObject
  1955. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_.Name }
  1956. break;
  1957. }
  1958.  
  1959. if ( $_param.TrimEnd("*") -eq "ev" -or $_param.TrimEnd("*") -eq "ov" -or
  1960. "ErrorVariable" -like $_param -or "OutVariable" -like $_param)
  1961. {
  1962. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort
  1963. break;
  1964. }
  1965.  
  1966. if ( "Tee-Object" -eq $_cmdlet.Name -and "Variable" -like $_param )
  1967. {
  1968. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort
  1969. break;
  1970. }
  1971.  
  1972. if ( "Clear-Variable", "Get-Variable", "New-Variable", "Remove-Variable", "Set-Variable" -contains $_cmdlet.Name `
  1973. -and "Name" -like $_param)
  1974. {
  1975. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1976. break;
  1977. }
  1978.  
  1979. if ( "Export-Alias", "Get-Alias", "New-Alias", "Set-Alias" -contains $_cmdlet.Name `
  1980. -and "Name" -like $_param)
  1981. {
  1982. Get-Alias -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1983. break;
  1984. }
  1985.  
  1986. if ( "Out-File","Export-CSV","Select-String","Export-Clixml" -contains $_cmdlet.Name `
  1987. -and "Encoding" -like $_param)
  1988. {
  1989. "Unicode",  "UTF7", "UTF8", "ASCII", "UTF32", "BigEndianUnicode", "Default", "OEM" |
  1990. ? { $_ -like $_opt } | sort -Unique
  1991. break;
  1992. }
  1993.  
  1994. if ( "Trace-Command","Get-TraceSource","Set-TraceSource" -contains $_cmdlet.Name `
  1995. -and "Name" -like $_param)
  1996. {
  1997. Get-TraceSource -Name $_opt | % { $_.Name } | sort -Unique | % { $_base + ($_ -replace '\s','` ') }
  1998. break;
  1999. }
  2000.  
  2001. if ( "New-Object" -like $_cmdlet.Name )
  2002. {
  2003. if ( "ComObject" -like $_param )
  2004. {
  2005. $_ProgID -like $_opt | % { $_ -replace '\s','` ' }
  2006. break;
  2007. }
  2008.  
  2009. if ( "TypeName" -like $_param )
  2010. {
  2011. if ( $_opt -eq "*" )
  2012. {
  2013. $_TypeAccelerators -like $_opt
  2014. }
  2015. else
  2016. {
  2017. $_TypeAccelerators -like $_opt
  2018. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1)
  2019. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1)
  2020. }
  2021. break;
  2022. }
  2023. }
  2024.  
  2025. if ( "New-Item" -eq $_cmdlet.Name )
  2026. {
  2027. if ( "ItemType" -like $_param )
  2028. {
  2029. "directory", "file" -like $_opt
  2030. break;
  2031. }
  2032. }
  2033.  
  2034. if ( "Get-Location", "Get-PSDrive", "Get-PSProvider", "New-PSDrive", "Remove-PSDrive" `
  2035. -contains $_cmdlet.Name `
  2036. -and "PSProvider" -like $_param )
  2037. {
  2038. Get-PSProvider -PSProvider $_opt | % { $_.Name } | sort  | % { $_base + ($_ -replace '\s','` ') }
  2039. break;
  2040. }
  2041.  
  2042. if ( "Get-Location" -eq $_cmdlet.Name -and "PSDrive" -like $_param )
  2043. {
  2044. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  2045. break;
  2046. }
  2047.  
  2048. if ( "Get-PSDrive", "New-PSDrive", "Remove-PSDrive" `
  2049. -contains $_cmdlet.Name -and "Name" -like $_param )
  2050. {
  2051. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  2052. break;
  2053. }
  2054.  
  2055. if ( "Get-Command" -eq $_cmdlet.Name -and  "PSSnapin" -like $_param)
  2056. {
  2057. if ( $global:_snapin -ne $null )
  2058. {
  2059. $global:_snapin -like $_opt  | % { $_base + $_ }
  2060. break;
  2061. }
  2062. else
  2063. {
  2064. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  2065. $global:_snapin -like $_opt  | % { $_base + ($_ -replace '\s','` ') }
  2066. break;
  2067. }
  2068. }
  2069.  
  2070. if ( "Add-PSSnapin", "Get-PSSnapin", "Remove-PSSnapin" `
  2071. -contains $_cmdlet.Name -and "Name" -like $_param )
  2072. {
  2073. if ( $global:_snapin -ne $null )
  2074. {
  2075. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  2076. break;
  2077. }
  2078. else
  2079. {
  2080. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  2081. $global:_snapin -like $_opt | % { $_base + $_ }
  2082. break;
  2083. }
  2084. }
  2085.  
  2086. if ( "Clear-Variable", "Export-Alias", "Get-Alias", "Get-PSDrive", "Get-Variable", "Import-Alias",
  2087. "New-Alias", "New-PSDrive", "New-Variable", "Remove-Variable", "Set-Alias", "Set-Variable" `
  2088. -contains $_cmdlet.Name -and "Scope" -like $_param )
  2089. {
  2090. "Global", "Local", "Script" -like $_opt
  2091. break;
  2092. }
  2093.  
  2094. if ( "Get-Process", "Stop-Process", "Wait-Process" -contains $_cmdlet.Name -and "Name" -like $_param )
  2095. {
  2096. Get-Process $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  2097. break;
  2098. }
  2099.  
  2100. if ( "Get-Eventlog" -eq $_cmdlet.Name -and "LogName" -like $_param )
  2101. {
  2102. Get-EventLog -List | ? { $_.Log -like $_opt } | % { $_base + ($_.Log -replace '\s','` ') }
  2103. break;
  2104. }
  2105.  
  2106. if ( "Get-Help" -eq $_cmdlet.Name -or "help" -eq $_cmdlet.Name )
  2107. {
  2108. if ( "Name" -like $_param )
  2109. {
  2110. Get-Help -Category all -Name $_opt | % { $_.Name } | sort -Unique
  2111. break;
  2112. }
  2113. if ( "Category" -like $_param )
  2114. {
  2115. "Alias", "Cmdlet", "Provider", "General", "FAQ",
  2116. "Glossary", "HelpFile", "All" -like $_opt | sort | % { $_base + $_ }
  2117. break;
  2118. }
  2119. }
  2120.  
  2121. if ( "Get-Service", "Restart-Service", "Resume-Service",
  2122. "Start-Service", "Stop-Service", "Suspend-Service" `
  2123. -contains $_cmdlet.Name )
  2124. {
  2125. if ( "Name" -like $_param )
  2126. {
  2127. Get-Service -Name $_opt | sort Name  | % { $_base + ($_.Name -replace '\s','` ') }
  2128. break;
  2129. }
  2130. if ( "DisplayName" -like $_param )
  2131. {
  2132. Get-Service -Name $_opt | sort DisplayName | % { $_base + ($_.DisplayName -replace '\s','` ') }
  2133. break;
  2134. }
  2135. }
  2136.  
  2137. if ( "New-Service" -eq $_cmdlet.Name -and "dependsOn" -like $_param )
  2138. {
  2139. Get-Service -Name $_opt | sort Name | % { $_base + ($_.Name -replace '\s','` ') }
  2140. break;
  2141. }
  2142.  
  2143. if ( "Get-EventLog" -eq $_cmdlet.Name -and "EntryType" -like $_param )
  2144. {
  2145. "Error", "Information", "FailureAudit", "SuccessAudit", "Warning" -like $_opt | sort | % { $_base + $_ }
  2146. break;
  2147. }
  2148.  
  2149. if ( "Get-Command" -eq $_cmdlet.Name -and "Name" -like $_param )
  2150. {
  2151. Get-Command -CommandType All -Name $_opt | % { $_base + ($_.Name -replace '\s','` ') }
  2152. break;
  2153. }
  2154.  
  2155. if ( $_cmdlet.Noun -like "*WMI*" )
  2156. {
  2157. if ( "Class" -like $_param )
  2158. {
  2159. Write-ClassNames $_WMIClasses ($_opt.Split("_").Count-1) -sep '_'
  2160. break;
  2161. }
  2162. }
  2163.  
  2164. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Compare-Object",
  2165. "ConvertTo-Html", "Measure-Object", "Select-Object", "Group-Object", "Sort-Object" `
  2166. -contains $_cmdlet.Name -and "Property" -like $_param )
  2167. {
  2168. Get-PipeLineObject
  2169. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  2170. break;
  2171. }
  2172.  
  2173. if ( "Select-Object" -eq $_cmdlet.Name )
  2174. {
  2175. if ( "ExcludeProperty" -like $_param )
  2176. {
  2177. Get-PipeLineObject
  2178. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  2179. break;
  2180. }
  2181.  
  2182. if ( "ExpandProperty" -like $_param )
  2183. {
  2184. Get-PipeLineObject
  2185. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_.Name }
  2186. break;
  2187. }
  2188. }
  2189.  
  2190. select -InputObject $_cmdlet -ExpandProperty ParameterSets | select -ExpandProperty Parameters |
  2191. ? { $_.Name -like $_param } | ? { $_.ParameterType.IsEnum } |
  2192. % { [Enum]::GetNames($_.ParameterType) } | ? { $_ -like $_opt } | sort -Unique | % { $_base + $_ }
  2193.  
  2194. }
  2195.  
  2196. if ($_tokens)
  2197. {
  2198. $_lastToken = $_tokens[$_tokens.count - 1]
  2199. if ($_lastToken.Type -eq 'Command')
  2200. {
  2201. $_cmd = $_lastToken.Content
  2202.  
  2203. # don't look for paths...
  2204. if ($_cmd.IndexOfAny('/\') -eq -1)
  2205. {
  2206. # handle parsing errors - the last token string should be the last
  2207. # string in the line...
  2208. if ($lastword.substring($lastword.length-$_cmd.length) -eq $_cmd)
  2209. {
  2210. $_pat = $_cmd + '*'
  2211. $_base = $lastword.substring(0, $lastword.length-$_cmd.length)
  2212. "begin {", "break", "catch {", "continue", "data {", "do {", "dynamicparam (", "else {", "elseif (",
  2213. "end {", "exit", "filter ", "finally {", "for (", "foreach ", "from", "function ", "if (", "in ",
  2214. "param (", "process {", "return", "switch ", "throw ", "trap ", "try {", "until (", "while (" `
  2215. -like $_pat | %  {'{0}{1}' -f $_base,$_ }
  2216. $ExecutionContext.InvokeCommand.GetCommandName($_pat,$true, $false) |
  2217. Sort-Object -Unique | ForEach-Object {'{0}{1}' -f $_base,$_ }
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. }
  2225. }

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