PoshCode Logo PowerShell Code Repository

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

Ported TabExpansion from V2CTP2 to v1.0 and extended. Please dot souce this script file to use.
Update:
Can cut and paste now!

  1. Cut current line with Ctrl+X

1: PS > <command><Ctrl+X><tab> # Cut current line
2: PS > <Ctrl+V><tab> # Paste a line that was copyed now

  1. Cut words with a charactor after Ctrl+X until the charactor

1: PS > dir Filter *.txt<Ctrl+X><tab> # Cut words until ‘-’
2: PS > dir – 3: PS > dir -<Ctrl+V><tab> # Paste words that were copyed now

  1. Cut last word in current line with Ctrl+Z

1: PS > Get-ChildItem *.txt<Ctrl+Z><tab> # Cut last word in current line
2: PS > Get-ChildItem
3: PS > Get-ChildItem -Exclude <Ctrl+V><tab> # Paste last word that was copyed now

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

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