PoshCode Logo PowerShell Code Repository

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

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

Several current date/time formats with Ctrl+D <Ctrl+D><tab><tab><tab><tab><tab>...

Hand-operated pop from command buffer with Ctrl+P (this is also available with ‘;:’ or ‘;,’) <command>;<tab> # push command <Ctrl+D><tab> # pop

Paste clipboard with Ctrl+V <Ctrl+V><tab>

BugFix:
It takes a long time to do regex with specific character strings.

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

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