PoshCode Logo PowerShell Code Repository

TabExpansion for V2CTP3 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/913"></script>download | new post

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

  1. ## Tab-Completion
  2. #################
  3. ## For V2CTP3.
  4. ## This won't work on V1 and V2CTP and V2CTP2.
  5. ## Please dot souce this script file.
  6. ## In first loading, it may take a several minutes, in order to generate ProgIDs and TypeNames list.
  7. ##
  8. ## What this can do is:
  9. ##
  10. ## [datetime]::n<tab>
  11. ## [datetime]::now.d<tab>
  12. ## $a = New-Object "Int32[,]" 2,3; $b = "PowerShell","PowerShell"
  13. ## $c = [ref]$a; $d = [ref]$b,$c
  14. ## $d[0].V<tab>[0][0].Get<tab>
  15. ## $d[1].V<tab>[0,0].tos<tab>
  16. ## $function:a<tab>
  17. ## $env:a<tab>
  18. ## [System.Type].a<tab>
  19. ## [datetime].Assembly.a<tab>
  20. ## ).a<tab> # shows System.Type properties and methods...
  21.  
  22. ## #native command name expansion
  23. ## fsu<tab>
  24.  
  25. ## #command option name expansion (for fsutil ipconfig net powershell only)
  26. ## fsutil <tab>
  27. ## ipconfig <tab>
  28. ## net <tab>
  29. ## powershell <tab>
  30.  
  31. ## #TypeNames and Type accelerators expansion
  32. ## [Dec<tab>
  33. ## [system.Man<tab>.auto<tab>.p<tab>
  34. ## New-Object -TypeName IO.Dir<tab>
  35. ## New-Object System.win<tab>.for<tab>.bu<tab>
  36.  
  37. ## #ProgIDs expansion
  38. ## New-Object -Com shel<tab>
  39.  
  40. ## #Enum option expansion
  41. ## Set-ExecutionPolicy <tab>
  42. ## Set-ExecutionPolicy All<tab>
  43. ## Set-ExcusionPolisy -ex <tab>
  44. ## Get-TraceSource Inte<tab>
  45. ## iex -Errora <tab> -wa Sil<tab>
  46.  
  47. ## #WmiClasses expansion
  48. ## Get-WmiObject -class Win32_<tab>
  49. ## gwmi __Instance<tab>
  50.  
  51. ## #Encoding expansion
  52. ## [Out-File | Export-CSV | Select-String | Export-Clixml] -enc <tab>
  53. ## [Add-Content | Get-Content | Set-Content} -Encoding Big<tab>
  54.  
  55. ## #PSProvider name expansion
  56. ## [Get-Location | Get-PSDrive | Get-PSProvider | New-PSDrive | Remove-PSDrive] -PSProvider <tab>
  57. ## Get-PSProvider <tab>
  58. ## pwd -psp al<tab>
  59.  
  60. ## #PSDrive name expansion
  61. ## [Get-PSDrive | New-PSDrive | Remove-PSDrive] [-Name] <tab>
  62. ## Get-PSDrive <tab>
  63. ## pwd -psd <tab>
  64.  
  65. ## #PSSnapin name expansion
  66. ## [Add-PSSnapin | Get-PSSnapin | Remove-PSSnapin ] [-Name] <tab>
  67. ## Get-Command -PSSnapin <tab>
  68. ## Remove-PSSnapin <tab>
  69. ## Get-PSSnapin M<tab>
  70.  
  71. ## #Eventlog name and expansion
  72. ## Get-Eventlog -Log <tab>
  73. ## Get-Eventlog w<tab>
  74.  
  75. ## #Eventlog's entrytype expansion
  76. ## Get-EventLog -EntryType <tab>
  77. ## Get-EventLog -EntryType Er<tab>
  78. ## Get-EventLog -Ent <tab>
  79.  
  80. ## #Service name expansion
  81. ## [Get-Service | Restart-Service | Resume-Service | Start-Service | Stop-Service | Suspend-Service] [-Name] <tab>
  82. ## New-Service -DependsOn <tab>
  83. ## New-Service -Dep e<tab>
  84. ## Get-Service -n <tab>
  85. ## Get-Service <tab>,a<tab>,p<tab>
  86. ## gsv <tab>
  87.  
  88. ## #Service display name expansion
  89. ## [Get-Service | Restart-Service | Resume-Service | Start-Service | Stop-Service | Suspend-Service] [-DisplayName] <tab>
  90. ## Get-Service -Dis <tab>
  91. ## gsv -Dis <tab>,w<tab>,b<tab>
  92.  
  93. ## #Cmdlet and Topic name expansion (this also support default help function and man alias)
  94. ## Get-Help [-Name] about_<tab>
  95. ## Get-Help <tab>
  96.  
  97. ## #Category name expansion (this also support default help function and man alias)
  98. ## Get-Help -Category c<tab>,<tab>
  99.  
  100. ## #Command name expansion
  101. ## Get-Command [-Name] <tab>
  102. ## Get-Command -Name <tab>
  103. ## gcm a<tab>,<tab>
  104.  
  105. ## #Scope expansion
  106. ## [Clear-Variable | Export-Alias | Get-Alias | Get-PSDrive | Get-Variable | Import-Alias
  107. ## New-Alias | New-PSDrive | New-Variable | Remove-Variable | Set-Alias | Set-Variable] -Scope <tab>
  108. ## Clear-Variable -Scope G<tab>
  109. ## Set-Alias  -s <tab>
  110.  
  111. ## #Process name expansion
  112. ## [Get-Process | Stop-Process] [-Name] <tab>
  113. ## Stop-Process -Name <tab>
  114. ## Stop-Process -N pow<tab>
  115. ## Get-Process <tab>
  116. ## ps power<tab>
  117.  
  118. ## #Trace sources expansion
  119. ## [Trace-Command | Get-TraceSource | Set-TraceSource] [-Name] <tab>,a<tab>,p<tab>
  120.  
  121. ## #Trace -ListenerOption expansion
  122. ## [Set-TraceSource | Trace-Command] -ListenerOption <tab>
  123. ## Set-TraceSource -Lis <tab>,n<tab>
  124.  
  125. ## #Trace -Option expansion
  126. ## [Set-TraceSource | Trace-Command] -Option <tab>
  127. ## Set-TraceSource -op <tab>,con<tab>
  128.  
  129. ## #ItemType expansion
  130. ## New-Item -Item <tab>
  131. ## ni -ItemType d<tab>
  132.  
  133. ## #ErrorAction and WarningAction option expansion
  134. ## CMDLET [-ErrorAction | -WarningAction] <tab>
  135. ## CMDLET -Errora s<tab>
  136. ## CMDLET -ea con<tab>
  137. ## CMDLET -wa <tab>
  138.  
  139. ## #Continuous expansion with comma when parameter can treat multiple option
  140. ## # if there are spaces, occur display bug in the line
  141. ## # if strings contains '$' or '-', not work
  142. ## Get-Command -CommandType <tab>,<tab><tab>,cm<tab>
  143. ## pwd -psp <tab>,f<tab>,va<tab>
  144. ## Get-EventLog -EntryType <tab>,i<tab>,s<tab>
  145.  
  146. ## #Enum expansion in method call expression
  147. ## # this needs one or more spaces after left parenthesis or comma
  148. ## $str = "day   night"
  149. ## $str.Split( " ",<space>rem<tab>
  150. ## >>> $str.Split( " ", "RemoveEmptyEntries" ) <Enter> ERROR
  151. ## $str.Split( " ", "RemoveEmptyEntries" -as<space><tab>
  152. ## >>> $str.Split( " ", "RemoveEmptyEntries" -as [System.StringSplitOptions] ) <Enter> Success
  153. ## $type = [System.Type]
  154. ## $type.GetMembers(<space>Def<tab>
  155. ## [IO.Directory]::GetFiles( "C:\", "*",<space>All<tab>
  156. ## # this can do continuous enum expansion with comma and no spaces
  157. ## $type.GetMembers( "IgnoreCase<comma>Dec<tab><comma>In<tab>"
  158. ## [IO.Directory]::GetAccessControl( "C:\",<space>au<tab><comma>ac<tab><comma>G<tab>
  159.  
  160. ## #Better '$_.' expansion when cmdlet output objects or method return objects
  161. ## ls |group { $_.Cr<tab>.Tost<tab>"y")} | tee -var foo| ? { $_.G<tab>.c<tab> -gt 5 } | % { md $_.N<tab> ; copy $_.G<tab> $_.N<tab>  }
  162. ## [IO.DriveInfo]::GetDrives() | ? { $_.A<tab> -gt 1GB }
  163. ## $Host.UI.RawUI.GetBufferContents($rect) | % { $str += $_.c<tab> }
  164. ## gcm Add-Content |select -exp Par<tab>| select -ExpandProperty Par<tab> | ? { $_.Par<tab>.N<tab> -eq "string" }
  165. ## $data = Get-Process
  166. ## $data[2,4,5]  | % { $_.<tab>
  167. ## #when Get-PipeLineObject failed, '$_.' shows methods and properties name of FileInfo and String and Type
  168.  
  169. ## #Property name expansion by -Property parameter
  170. ## [ Format-List | Format-Custom | Format-Table | Format-Wide | Compare-Object |
  171. ##  ConvertTo-Html | Measure-Object | Select-Object | Group-Object | Sort-Object ] [-Property] <tab>
  172. ## Select-Object -ExcludeProperty <tab>
  173. ## Select-Object -ExpandProperty <tab>
  174. ## gcm Get-Acl|select -exp Par<tab>
  175. ## ps |group na<tab>
  176. ## ls | ft A<tab>,M<tab>,L<tab>
  177.  
  178. ## #Hashtable key expansion in the variable name and '.<tab>'
  179. ## Get-Process | Get-Unique | % { $hash += @{$_.ProcessName=$_} }
  180. ## $hash.pow<tab>.pro<tab>
  181.  
  182. ## #Parameter expansion for function, filter and script
  183. ## man -f<tab>
  184. ## 'param([System.StringSplitOptions]$foo,[System.Management.Automation.ActionPreference]$bar,[System.Management.Automation.CommandTypes]$baz) {}' > foobar.ps1
  185. ## .\foobar.ps1 -<tab> -b<tab>
  186.  
  187. ## #Enum expansion for function, filter and scripts
  188. ## # this can do continuous enum expansion with comma and no spaces
  189. ## .\foobar.ps1 -foo rem<tab> -bar <tab><comma>c<tab><comma>sc<tab> -ea silent<tab> -wa con<tab>
  190.  
  191. ## #Enum expansion for assignment expression
  192. ## #needs space(s) after '=' and comma
  193. ## #strongly-typed with -as operator and space(s)
  194. ## $ErrorActionPreference =<space><tab>
  195. ## $cmdtypes = New-Object System.Management.Automation.CommandTypes[] 3
  196. ## $cmdtypes =<space><tab><comma><space>func<tab><comma><space>cmd<tab> -as<space><tab>
  197.  
  198. ## #Path expansion with variable and '\' or '/'
  199. ## $PWD\../../<tab>\<tab>
  200. ## "$env:SystemDrive/pro<tab>/<tab>
  201.  
  202. ## #Operator expansion which starts with '-'
  203. ## "Power","Shell" -m<tab> "Power" -r<tab> '(Pow)(er)','$1d$2'
  204. ## 1..9 -co<tab> 5
  205.  
  206. ## #Keyword expansion
  207. ## fu<tab> test { p<tab> $foo, $bar ) b<tab> "foo" } pr<tab> $_ } en<tab> "$bar" } }
  208.  
  209. ## #Variable name expansion (only global scope)
  210. ## [Clear-Variable | Get-Variable | New-Variable | Remove-Variable | Set-Variable] [-Name] <tab>
  211. ## [Cmdlet | Function | Filter | ExternalScript] -ErrorVariable <tab>
  212. ## [Cmdlet | Function | Filter | ExternalScript] -OutVariable <tab>
  213. ## Tee-Object -Variable <tab>
  214. ##  gv pro<tab>,<tab>
  215. ##  Remove-Variable -Name out<tab>,<tab>,ps<tab>
  216. ##  ... | ... | tee -v <tab>
  217.  
  218. ## #Alias name expansion
  219. ## [Get-Alias | New-Alias | Set-Alias] [-Name] <tab>
  220. ## Export-Alias -Name <tab>
  221. ##  Get-Alias i<tab>,e<tab>,a<tab>
  222. ##  epal -n for<tab>
  223.  
  224. ## #Property name expansion with -groupBy parameter
  225. ## [Format-List | Format-Custom | Format-Table | Format-Wide] -groupBy <tab>
  226. ##  ps | ft -g <tab>
  227. ##  gcm | Format-Wide -GroupBy Par<tab>
  228.  
  229. ## #Type accelerators expansion with no charactors
  230. ##  [<tab>
  231. ##  New-Object -typename <tab>
  232. ##  New-Object <tab>
  233.  
  234. ## # File glob expansion with '@'
  235. ##  ls *.txt@<tab>
  236. ##  ls file.txt, foo1.txt, 'bar``[1``].txt', 'foo bar .txt'     # 1 <tab> expanding with comma
  237. ##  ls * -Filter *.txt                                          # 2 <tab> refactoring
  238. ##  ls *.txt                                                    # 3 <tab> (or 1 <tab> & 1 <shift>+<tab>) return original glob pattern
  239.  
  240. ## This can also use '^'(hat) or '~'(tilde) for Excluding
  241. ##  ls <hat>*.txt@<tab>
  242. ##  ls foo.ps1, 'bar``[1``].xml'                # 1 <tab> expanding with comma
  243. ##  ls * -Filter * -Excluding *.txt             # 2 <tab> refactoring
  244. ##  *.txt<tilde>foo*<tilde>bar*@<tab>
  245. ##  ls file.txt                                 # 1 <tab> expanding with comma
  246. ##  ls * -Filter *.txt -Excluding foo*, bar*    # 2 <tab> refactoring
  247.  
  248. ## # Ported history expansion from V2CTP3 TabExpansion with '#' ( #<pattern> or #<id> )
  249. ##  ls * -Filter * -Excluding foo*, bar*<Enter>
  250. ##  #ls<tab>
  251. ##  #1<tab>
  252.  
  253. ## # Command buffer stack with ';'(semicolon)
  254. ##  ls * -Filter * -Excluding foo*, bar*<semicolon><tab> # push command1
  255. ##  echo "PowerShell"<semicolon><tab> # push command2
  256. ##  get-process<semicolon><tab> # push command3
  257. ##  {COMMAND}<Enter> # execute another command
  258. ##  get-process # Auto pop command3 from stack by LIFO
  259. ## This can also hand-operated pop with ';,'(semicolon&comma) or ';:'(semicolon&colon)
  260. ##  get-process; <semicolon><comma><tab>
  261. ##  get-process; echo "PowerShell" # pop command2 from stack by LIFO
  262.  
  263. ## # Function name expansion after 'function' or 'filter' keywords
  264. ## function cl<tab>
  265.  
  266. ## #Switch syntax option expansion
  267. ##  switch -w<tab> -f<tab>
  268.  
  269. ## #Better powershell.exe option expansion with '-'
  270. ##  powershell -no<tab> -<tab> -en<tab>
  271.  
  272. ## #A part of PowerShell attributes expansion ( CmdletBinding, Parameter, Alias, Validate*, Allow* )
  273. ##  [par<tab>
  274. ##  [cmd<tab>
  275.  
  276. ## #Member expansion for CmdletBinding and Parameter attributes
  277. ##  [Parameter(man<tab>,<tab>1,val<tab>$true)]
  278. ##  [CmdletBinding( <tab>"foo", su<tab>$true)]
  279.  
  280. ## #Several current date/time formats with Ctrl+D
  281. ##  <Ctrl+D><tab><tab><tab><tab><tab>...
  282.  
  283. ## #Hand-operated pop from command buffer with Ctrl+P (this is also available with ';:' or ';,')
  284. ##  <command>;<tab> # push command
  285. ##  <Ctrl+D><tab> # pop
  286.  
  287. ## #Paste clipboard with Ctrl+V
  288. ##  <Ctrl+V><tab>
  289.  
  290. ### 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 = [type]::gettype("System.Management.Automation.TypeAccelerators")::get.keys | sort
  369.  
  370. iex (@'
  371. function prompt {
  372. if ($_cmdstack.Count -gt 0) {
  373. $line = $global:_cmdstack.Pop() -replace '([[\]\(\)+{}?~%])','{$1}'
  374. [System.Windows.Forms.SendKeys]::SendWait($line)
  375. }
  376. '@ + @"
  377. ${function:prompt}
  378. }
  379. "@)
  380.  
  381. function Write-ClassNames ( $data, $i, $prefix='', $sep='.' )
  382. {
  383. $preItem = ""
  384. foreach ( $class in $data -like $_opt )
  385. {
  386. $Item = $class.Split($sep)
  387. if ( $preItem -ne $Item[$i] )
  388. {
  389. if ( $i+1 -eq $Item.Count )
  390. {
  391. if ( $prefix -eq "[" )
  392. {
  393. $suffix = "]"
  394. }
  395. elseif ( $sep -eq "_" )
  396. {
  397. $suffix = ""
  398. }
  399. else
  400. {
  401. $suffix = " "
  402. }
  403. }
  404. else
  405. {
  406. $suffix = ""
  407. }
  408. $prefix + $_opt.Substring(0, $_opt.LastIndexOf($sep)+1) + $Item[$i] + $suffix
  409.  
  410. $preItem = $Item[$i]
  411. }
  412. }
  413. }
  414.  
  415. function Get-PipeLineObject {
  416.  
  417. $i = -2
  418. $property = $null
  419. do {
  420. $str = $line.Split("|")
  421. # extract the command name from the string
  422. # first split the string into statements and pipeline elements
  423. # This doesn't handle strings however.
  424. $_cmdlet = [regex]::Split($str[$i], '[|;=]')[-1]
  425.  
  426. # take the first space separated token of the remaining string
  427. # as the command to look up. Trim any leading or trailing spaces
  428. # so you don't get leading empty elements.
  429. $_cmdlet = $_cmdlet.Trim().Split()[0]
  430.  
  431. if ( $_cmdlet -eq "?" )
  432. {
  433. $_cmdlet = "Where-Object"
  434. }
  435.  
  436. $global:_exp = $_cmdlet
  437.  
  438. # now get the info object for it...
  439. $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet)[0]
  440.  
  441. # loop resolving aliases...
  442. while ($_cmdlet.CommandType -eq 'alias')
  443. {
  444. $_cmdlet = @(Get-Command -type 'cmdlet,alias' $_cmdlet.Definition)[0]
  445. }
  446.  
  447. if ( "Select-Object" -eq $_cmdlet )
  448. {
  449. if ( $str[$i] -match '\s+-Exp\w*[\s:]+(\w+)' )
  450. {
  451. $property = $Matches[1] + ";" + $property
  452. }
  453. }
  454.  
  455. $i--
  456. } while ( "Get-Unique", "Select-Object", "Sort-Object", "Tee-Object", "Where-Object" -contains $_cmdlet )
  457.  
  458. if ( $global:_forgci -eq $null )
  459. {
  460. $a = @(ls "Alias:\")[0]
  461. $e = @(ls "Env:\")[0]
  462. $f = @(ls "Function:\")[0]
  463. $h = @(ls "HKCU:\")[0]
  464. $v = @(ls "Variable:\")[0]
  465. $c = @(ls "cert:\")[0]
  466. $global:_forgci = gi $PSHOME\powershell.exe |
  467. Add-Member  'NoteProperty'  CommandType  $f.CommandType -P |
  468. Add-Member  'NoteProperty'  Definition  $a.Definition -P |
  469. Add-Member  'NoteProperty'  Description  $a.Description -P |
  470. Add-Member  'NoteProperty'  Key  $e.Key -P |
  471. Add-Member  'NoteProperty'  Location  $c.Location -P |
  472. Add-Member  'NoteProperty'  LocationName  $c.LocationName -P |
  473. Add-Member  'NoteProperty'  Options  $a.Options -P |
  474. Add-Member  'NoteProperty'  ReferencedCommand  $a.ReferencedCommand -P |
  475. Add-Member  'NoteProperty'  ResolvedCommand  $a.ResolvedCommand -P |
  476. Add-Member  'NoteProperty'  ScriptBlock  $f.ScriptBlock -P |
  477. Add-Member  'NoteProperty'  StoreNames  $c.StoreNames -P |
  478. Add-Member  'NoteProperty'  SubKeyCount  $h.SubKeyCount -P |
  479. Add-Member  'NoteProperty'  Value  $e.Value -P |
  480. Add-Member  'NoteProperty'  ValueCount  $h.ValueCount -P |
  481. Add-Member  'NoteProperty'  Visibility  $a.Visibility -P |
  482. Add-Member  'NoteProperty'  Property  $h.Property -P |
  483. Add-Member  'NoteProperty'  ResolvedCommandName  $a.ResolvedCommandName -P |
  484. Add-Member  'ScriptMethod'  Close  {} -P |
  485. Add-Member  'ScriptMethod'  CreateSubKey  {} -P |
  486. Add-Member  'ScriptMethod'  DeleteSubKey  {} -P |
  487. Add-Member  'ScriptMethod'  DeleteSubKeyTree  {} -P |
  488. Add-Member  'ScriptMethod'  DeleteValue  {} -P |
  489. Add-Member  'ScriptMethod'  Flush  {} -P |
  490. Add-Member  'ScriptMethod'  GetSubKeyNames  {} -P |
  491. Add-Member  'ScriptMethod'  GetValue  {} -P |
  492. Add-Member  'ScriptMethod'  GetValueKind  {} -P |
  493. Add-Member  'ScriptMethod'  GetValueNames  {} -P |
  494. Add-Member  'ScriptMethod'  IsValidValue  {} -P |
  495. Add-Member  'ScriptMethod'  OpenSubKey  {} -P |
  496. Add-Member  'ScriptMethod'  SetValue  {} -P
  497. }
  498.  
  499. if ( $global:_mix -eq $null )
  500. {
  501. $f = gi $PSHOME\powershell.exe
  502. $t = [type]
  503. $s = ""
  504. $global:_mix = `
  505. Add-Member -InputObject (New-Object PSObject)  'NoteProperty'  Mode  $f.Mode -P |
  506. Add-Member  'NoteProperty'  Assembly  $t.Assembly -P |
  507. Add-Member  'NoteProperty'  AssemblyQualifiedName  $t.AssemblyQualifiedName -P |
  508. Add-Member  'NoteProperty'  Attributes  $f.Attributes -P |
  509. Add-Member  'NoteProperty'  BaseType  $t.BaseType -P |
  510. Add-Member  'NoteProperty'  ContainsGenericParameters  $t.ContainsGenericParameters -P |
  511. Add-Member  'NoteProperty'  CreationTime  $f.CreationTime -P |
  512. Add-Member  'NoteProperty'  CreationTimeUtc  $f.CreationTimeUtc -P |
  513. Add-Member  'NoteProperty'  DeclaringMethod  $t.DeclaringMethod -P |
  514. Add-Member  'NoteProperty'  DeclaringType  $t.DeclaringType -P |
  515. Add-Member  'NoteProperty'  Exists  $f.Exists -P |
  516. Add-Member  'NoteProperty'  Extension  $f.Extension -P |
  517. Add-Member  'NoteProperty'  FullName  $f.FullName -P |
  518. Add-Member  'NoteProperty'  GenericParameterAttributes  $t.GenericParameterAttributes -P |
  519. Add-Member  'NoteProperty'  GenericParameterPosition  $t.GenericParameterPosition -P |
  520. Add-Member  'NoteProperty'  GUID  $t.GUID -P |
  521. Add-Member  'NoteProperty'  HasElementType  $t.HasElementType -P |
  522. Add-Member  'NoteProperty'  IsAbstract  $t.IsAbstract -P |
  523. Add-Member  'NoteProperty'  IsAnsiClass  $t.IsAnsiClass -P |
  524. Add-Member  'NoteProperty'  IsArray  $t.IsArray -P |
  525. Add-Member  'NoteProperty'  IsAutoClass  $t.IsAutoClass -P |
  526. Add-Member  'NoteProperty'  IsAutoLayout  $t.IsAutoLayout -P |
  527. Add-Member  'NoteProperty'  IsByRef  $t.IsByRef -P |
  528. Add-Member  'NoteProperty'  IsClass  $t.IsClass -P |
  529. Add-Member  'NoteProperty'  IsCOMObject  $t.IsCOMObject -P |
  530. Add-Member  'NoteProperty'  IsContextful  $t.IsContextful -P |
  531. Add-Member  'NoteProperty'  IsEnum  $t.IsEnum -P |
  532. Add-Member  'NoteProperty'  IsExplicitLayout  $t.IsExplicitLayout -P |
  533. Add-Member  'NoteProperty'  IsGenericParameter  $t.IsGenericParameter -P |
  534. Add-Member  'NoteProperty'  IsGenericType  $t.IsGenericType -P |
  535. Add-Member  'NoteProperty'  IsGenericTypeDefinition  $t.IsGenericTypeDefinition -P |
  536. Add-Member  'NoteProperty'  IsImport  $t.IsImport -P |
  537. Add-Member  'NoteProperty'  IsInterface  $t.IsInterface -P |
  538. Add-Member  'NoteProperty'  IsLayoutSequential  $t.IsLayoutSequential -P |
  539. Add-Member  'NoteProperty'  IsMarshalByRef  $t.IsMarshalByRef -P |
  540. Add-Member  'NoteProperty'  IsNested  $t.IsNested -P |
  541. Add-Member  'NoteProperty'  IsNestedAssembly  $t.IsNestedAssembly -P |
  542. Add-Member  'NoteProperty'  IsNestedFamANDAssem  $t.IsNestedFamANDAssem -P |
  543. Add-Member  'NoteProperty'  IsNestedFamily  $t.IsNestedFamily -P |
  544. Add-Member  'NoteProperty'  IsNestedFamORAssem  $t.IsNestedFamORAssem -P |
  545. Add-Member  'NoteProperty'  IsNestedPrivate  $t.IsNestedPrivate -P |
  546. Add-Member  'NoteProperty'  IsNestedPublic  $t.IsNestedPublic -P |
  547. Add-Member  'NoteProperty'  IsNotPublic  $t.IsNotPublic -P |
  548. Add-Member  'NoteProperty'  IsPointer  $t.IsPointer -P |
  549. Add-Member  'NoteProperty'  IsPrimitive  $t.IsPrimitive -P |
  550. Add-Member  'NoteProperty'  IsPublic  $t.IsPublic -P |
  551. Add-Member  'NoteProperty'  IsSealed  $t.IsSealed -P |
  552. Add-Member  'NoteProperty'  IsSerializable  $t.IsSerializable -P |
  553. Add-Member  'NoteProperty'  IsSpecialName  $t.IsSpecialName -P |
  554. Add-Member  'NoteProperty'  IsUnicodeClass  $t.IsUnicodeClass -P |
  555. Add-Member  'NoteProperty'  IsValueType  $t.IsValueType -P |
  556. Add-Member  'NoteProperty'  IsVisible  $t.IsVisible -P |
  557. Add-Member  'NoteProperty'  LastAccessTime  $f.LastAccessTime -P |
  558. Add-Member  'NoteProperty'  LastAccessTimeUtc  $f.LastAccessTimeUtc -P |
  559. Add-Member  'NoteProperty'  LastWriteTime  $f.LastWriteTime -P |
  560. Add-Member  'NoteProperty'  LastWriteTimeUtc  $f.LastWriteTimeUtc -P |
  561. Add-Member  'NoteProperty'  MemberType  $t.MemberType -P |
  562. Add-Member  'NoteProperty'  MetadataToken  $t.MetadataToken -P |
  563. Add-Member  'NoteProperty'  Module  $t.Module -P |
  564. Add-Member  'NoteProperty'  Name  $t.Name -P |
  565. Add-Member  'NoteProperty'  Namespace  $t.Namespace -P |
  566. Add-Member  'NoteProperty'  Parent  $f.Parent -P |
  567. Add-Member  'NoteProperty'  ReflectedType  $t.ReflectedType -P |
  568. Add-Member  'NoteProperty'  Root  $f.Root -P |
  569. Add-Member  'NoteProperty'  StructLayoutAttribute  $t.StructLayoutAttribute -P |
  570. Add-Member  'NoteProperty'  TypeHandle  $t.TypeHandle -P |
  571. Add-Member  'NoteProperty'  TypeInitializer  $t.TypeInitializer -P |
  572. Add-Member  'NoteProperty'  UnderlyingSystemType  $t.UnderlyingSystemType -P |
  573. Add-Member  'NoteProperty'  PSChildName  $f.PSChildName -P |
  574. Add-Member  'NoteProperty'  PSDrive  $f.PSDrive -P |
  575. Add-Member  'NoteProperty'  PSIsContainer  $f.PSIsContainer -P |
  576. Add-Member  'NoteProperty'  PSParentPath  $f.PSParentPath -P |
  577. Add-Member  'NoteProperty'  PSPath  $f.PSPath -P |
  578. Add-Member  'NoteProperty'  PSProvider  $f.PSProvider -P |
  579. Add-Member  'NoteProperty'  BaseName  $f.BaseName -P |
  580. Add-Member  'ScriptMethod'  Clone  {} -P |
  581. Add-Member  'ScriptMethod'  CompareTo  {} -P |
  582. Add-Member  'ScriptMethod'  Contains  {} -P |
  583. Add-Member  'ScriptMethod'  CopyTo  {} -P |
  584. Add-Member  'ScriptMethod'  Create  {} -P |
  585. Add-Member  'ScriptMethod'  CreateObjRef  {} -P |
  586. Add-Member  'ScriptMethod'  CreateSubdirectory  {} -P |
  587. Add-Member  'ScriptMethod'  Delete  {} -P |
  588. Add-Member  'ScriptMethod'  EndsWith  {} -P |
  589. Add-Member  'ScriptMethod'  FindInterfaces  {} -P |
  590. Add-Member  'ScriptMethod'  FindMembers  {} -P |
  591. Add-Member  'ScriptMethod'  GetAccessControl  {} -P |
  592. Add-Member  'ScriptMethod'  GetArrayRank  {} -P |
  593. Add-Member  'ScriptMethod'  GetConstructor  {} -P |
  594. Add-Member  'ScriptMethod'  GetConstructors  {} -P |
  595. Add-Member  'ScriptMethod'  GetCustomAttributes  {} -P |
  596. Add-Member  'ScriptMethod'  GetDefaultMembers  {} -P |
  597. Add-Member  'ScriptMethod'  GetDirectories  {} -P |
  598. Add-Member  'ScriptMethod'  GetElementType  {} -P |
  599. Add-Member  'ScriptMethod'  GetEnumerator  {} -P |
  600. Add-Member  'ScriptMethod'  GetEvent  {} -P |
  601. Add-Member  'ScriptMethod'  GetEvents  {} -P |
  602. Add-Member  'ScriptMethod'  GetField  {} -P |
  603. Add-Member  'ScriptMethod'  GetFields  {} -P |
  604. Add-Member  'ScriptMethod'  GetFiles  {} -P |
  605. Add-Member  'ScriptMethod'  GetFileSystemInfos  {} -P |
  606. Add-Member  'ScriptMethod'  GetGenericArguments  {} -P |
  607. Add-Member  'ScriptMethod'  GetGenericParameterConstraints  {} -P |
  608. Add-Member  'ScriptMethod'  GetGenericTypeDefinition  {} -P |
  609. Add-Member  'ScriptMethod'  GetInterface  {} -P |
  610. Add-Member  'ScriptMethod'  GetInterfaceMap  {} -P |
  611. Add-Member  'ScriptMethod'  GetInterfaces  {} -P |
  612. Add-Member  'ScriptMethod'  GetLifetimeService  {} -P |
  613. Add-Member  'ScriptMethod'  GetMember  {} -P |
  614. Add-Member  'ScriptMethod'  GetMembers  {} -P |
  615. Add-Member  'ScriptMethod'  GetMethod  {} -P |
  616. Add-Member  'ScriptMethod'  GetMethods  {} -P |
  617. Add-Member  'ScriptMethod'  GetNestedType  {} -P |
  618. Add-Member  'ScriptMethod'  GetNestedTypes  {} -P |
  619. Add-Member  'ScriptMethod'  GetObjectData  {} -P |
  620. Add-Member  'ScriptMethod'  GetProperties  {} -P |
  621. Add-Member  'ScriptMethod'  GetProperty  {} -P |
  622. Add-Member  'ScriptMethod'  GetTypeCode  {} -P |
  623. Add-Member  'ScriptMethod'  IndexOf  {} -P |
  624. Add-Member  'ScriptMethod'  IndexOfAny  {} -P |
  625. Add-Member  'ScriptMethod'  InitializeLifetimeService  {} -P |
  626. Add-Member  'ScriptMethod'  Insert  {} -P |
  627. Add-Member  'ScriptMethod'  InvokeMember  {} -P |
  628. Add-Member  'ScriptMethod'  IsAssignableFrom  {} -P |
  629. Add-Member  'ScriptMethod'  IsDefined  {} -P |
  630. Add-Member  'ScriptMethod'  IsInstanceOfType  {} -P |
  631. Add-Member  'ScriptMethod'  IsNormalized  {} -P |
  632. Add-Member  'ScriptMethod'  IsSubclassOf  {} -P |
  633. Add-Member  'ScriptMethod'  LastIndexOf  {} -P |
  634. Add-Member  'ScriptMethod'  LastIndexOfAny  {} -P |
  635. Add-Member  'ScriptMethod'  MakeArrayType  {} -P |
  636. Add-Member  'ScriptMethod'  MakeByRefType  {} -P |
  637. Add-Member  'ScriptMethod'  MakeGenericType  {} -P |
  638. Add-Member  'ScriptMethod'  MakePointerType  {} -P |
  639. Add-Member  'ScriptMethod'  MoveTo  {} -P |
  640. Add-Member  'ScriptMethod'  Normalize  {} -P |
  641. Add-Member  'ScriptMethod'  PadLeft  {} -P |
  642. Add-Member  'ScriptMethod'  PadRight  {} -P |
  643. Add-Member  'ScriptMethod'  Refresh  {} -P |
  644. Add-Member  'ScriptMethod'  Remove  {} -P |
  645. Add-Member  'ScriptMethod'  Replace  {} -P |
  646. Add-Member  'ScriptMethod'  SetAccessControl  {} -P |
  647. Add-Member  'ScriptMethod'  Split  {} -P |
  648. Add-Member  'ScriptMethod'  StartsWith  {} -P |
  649. Add-Member  'ScriptMethod'  Substring  {} -P |
  650. Add-Member  'ScriptMethod'  ToCharArray  {} -P |
  651. Add-Member  'ScriptMethod'  ToLower  {} -P |
  652. Add-Member  'ScriptMethod'  ToLowerInvariant  {} -P |
  653. Add-Member  'ScriptMethod'  ToUpper  {} -P |
  654. Add-Member  'ScriptMethod'  ToUpperInvariant  {} -P |
  655. Add-Member  'ScriptMethod'  Trim  {} -P |
  656. Add-Member  'ScriptMethod'  TrimEnd  {} -P |
  657. Add-Member  'ScriptMethod'  TrimStart  {} -P |
  658. Add-Member  'NoteProperty'  Chars  $s.Chars -P
  659. }
  660.  
  661.  
  662. if ( "Add-Member" -eq $_cmdlet )
  663. {
  664. $global:_dummy = $null
  665. }
  666.  
  667.  
  668. if ( "Compare-Object" -eq $_cmdlet )
  669. {
  670. $global:_dummy =  (Compare-Object 1 2)[0]
  671. }
  672.  
  673.  
  674. if ( "ConvertFrom-SecureString" -eq $_cmdlet )
  675. {
  676. $global:_dummy = $null
  677. }
  678.  
  679.  
  680. if ( "ConvertTo-SecureString" -eq $_cmdlet )
  681. {
  682. $global:_dummy = convertto-securestring "P@ssW0rD!" -asplaintext -force
  683. }
  684.  
  685.  
  686. if ( "ForEach-Object" -eq $_cmdlet )
  687. {
  688. $global:_dummy = $null
  689. }
  690.  
  691.  
  692. if ( "Get-Acl" -eq $_cmdlet )
  693. {
  694. $global:_dummy = Get-Acl
  695. }
  696.  
  697.  
  698. if ( "Get-Alias" -eq $_cmdlet )
  699. {
  700. $global:_dummy = (Get-Alias)[0]
  701. }
  702.  
  703.  
  704. if ( "Get-AuthenticodeSignature" -eq $_cmdlet )
  705. {
  706. $global:_dummy = Get-AuthenticodeSignature $PSHOME\powershell.exe
  707. }
  708.  
  709.  
  710. if ( "Get-ChildItem" -eq $_cmdlet )
  711. {
  712. $global:_dummy = $global:_forgci
  713. }
  714.  
  715.  
  716. if ( "Get-Command" -eq $_cmdlet )
  717. {
  718. $global:_dummy = @(iex $str[$i+1])[0]
  719. }
  720.  
  721.  
  722. if ( "Get-Content" -eq $_cmdlet )
  723. {
  724. $global:_dummy = (type $PSHOME\profile.ps1)[0]
  725. }
  726.  
  727.  
  728. if ( "Get-Credential" -eq $_cmdlet )
  729. {
  730. $global:_dummy = $null
  731. }
  732.  
  733.  
  734. if ( "Get-Culture" -eq $_cmdlet )
  735. {
  736. $global:_dummy = Get-Culture
  737. }
  738.  
  739.  
  740. if ( "Get-Date" -eq $_cmdlet )
  741. {
  742. $global:_dummy = Get-Date
  743. }
  744.  
  745.  
  746. if ( "Get-Event" -eq $_cmdlet )
  747. {
  748. $global:_dummy = (Get-Event)[0]
  749. }
  750.  
  751.  
  752. if ( "Get-EventLog" -eq $_cmdlet )
  753. {
  754. $global:_dummy = @(iex $str[$i+1])[0]
  755. }
  756.  
  757.  
  758. if ( "Get-ExecutionPolicy" -eq $_cmdlet )
  759. {
  760. $global:_dummy = Get-ExecutionPolicy
  761. }
  762.  
  763.  
  764. if ( "Get-Help" -eq $_cmdlet )
  765. {
  766. $global:_dummy = Get-Help Add-Content
  767. }
  768.  
  769.  
  770. if ( "Get-History" -eq $_cmdlet )
  771. {
  772. $global:_dummy = Get-History -Count 1
  773. }
  774.  
  775.  
  776. if ( "Get-Host" -eq $_cmdlet )
  777. {
  778. $global:_dummy = Get-Host
  779. }
  780.  
  781.  
  782. if ( "Get-Item" -eq $_cmdlet )
  783. {
  784. $global:_dummy = $global:_forgci
  785. }
  786.  
  787.  
  788. if ( "Get-ItemProperty" -eq $_cmdlet )
  789. {
  790. $global:_dummy = $null
  791. }
  792.  
  793.  
  794. if ( "Get-Location" -eq $_cmdlet )
  795. {
  796. $global:_dummy = Get-Location
  797. }
  798.  
  799.  
  800. if ( "Get-Member" -eq $_cmdlet )
  801. {
  802. $global:_dummy = (1|Get-Member)[0]
  803. }
  804.  
  805.  
  806. if ( "Get-Module" -eq $_cmdlet )
  807. {
  808. $global:_dummy = (Get-Module)[0]
  809. }
  810.  
  811.  
  812. if ( "Get-PfxCertificate" -eq $_cmdlet )
  813. {
  814. $global:_dummy = $null
  815. }
  816.  
  817.  
  818. if ( "Get-Process" -eq $_cmdlet )
  819. {
  820. $global:_dummy = ps powershell
  821. }
  822.  
  823.  
  824. if ( "Get-PSBreakpoint" -eq $_cmdlet )
  825. {
  826. $global:_dummy =
  827. Add-Member -InputObject (New-Object PSObject)  'NoteProperty'  Action  '' -P |
  828. Add-Member  'NoteProperty'  Command  '' -P |
  829. Add-Member  'NoteProperty'  Enabled  '' -P |
  830. Add-Member  'NoteProperty'  HitCount  '' -P |
  831. Add-Member  'NoteProperty'  Id  '' -P |
  832. Add-Member  'NoteProperty'  Script  '' -P
  833. }
  834.  
  835.  
  836. if ( "Get-PSCallStack" -eq $_cmdlet )
  837. {
  838. $global:_dummy = Get-PSCallStack
  839. }
  840.  
  841.  
  842. if ( "Get-PSDrive" -eq $_cmdlet )
  843. {
  844. $global:_dummy = Get-PSDrive Function
  845. }
  846.  
  847.  
  848. if ( "Get-PSProvider" -eq $_cmdlet )
  849. {
  850. $global:_dummy = Get-PSProvider FileSystem
  851. }
  852.  
  853.  
  854. if ( "Get-PSSnapin" -eq $_cmdlet )
  855. {
  856. $global:_dummy = Get-PSSnapin Microsoft.PowerShell.Core
  857. }
  858.  
  859.  
  860. if ( "Get-Service" -eq $_cmdlet )
  861. {
  862. $global:_dummy = (Get-Service)[0]
  863. }
  864.  
  865.  
  866. if ( "Get-TraceSource" -eq $_cmdlet )
  867. {
  868. $global:_dummy = Get-TraceSource AddMember
  869. }
  870.  
  871.  
  872. if ( "Get-UICulture" -eq $_cmdlet )
  873. {
  874. $global:_dummy = Get-UICulture
  875. }
  876.  
  877.  
  878. if ( "Get-Variable" -eq $_cmdlet )
  879. {
  880. $global:_dummy = Get-Variable _
  881. }
  882.  
  883.  
  884. if ( "Get-WmiObject" -eq $_cmdlet )
  885. {
  886. $global:_dummy = @(iex $str[$i+1])[0]
  887. }
  888.  
  889.  
  890. if ( "Group-Object" -eq $_cmdlet )
  891. {
  892. $global:_dummy = 1 | group
  893. }
  894.  
  895.  
  896. if ( "Measure-Command" -eq $_cmdlet )
  897. {
  898. $global:_dummy = Measure-Command {}
  899. }
  900.  
  901.  
  902. if ( "Measure-Object" -eq $_cmdlet )
  903. {
  904. $global:_dummy = Measure-Object
  905. }
  906.  
  907.  
  908. if ( "New-PSDrive" -eq $_cmdlet )
  909. {
  910. $global:_dummy =  Get-PSDrive Alias
  911. }
  912.  
  913.  
  914. if ( "New-TimeSpan" -eq $_cmdlet )
  915. {
  916. $global:_dummy = New-TimeSpan
  917. }
  918.  
  919.  
  920. if ( "Resolve-Path" -eq $_cmdlet )
  921. {
  922. $global:_dummy = $PWD
  923. }
  924.  
  925.  
  926. if ( "Select-String" -eq $_cmdlet )
  927. {
  928. $global:_dummy = " " | Select-String " "
  929. }
  930.  
  931.  
  932. if ( "Set-Date" -eq $_cmdlet )
  933. {
  934. $global:_dummy =  Get-Date
  935. }
  936.  
  937. if ( $property -ne $null)
  938. {
  939. foreach ( $name in $property.Split(";", "RemoveEmptyEntries" -as [System.StringSplitOptions]) )
  940. {
  941. $global:_dummy = @($global:_dummy.$name)[0]
  942. }
  943. }
  944. }
  945.  
  946.  
  947. function TabExpansion {
  948. # This is the default function to use for tab expansion. It handles simple
  949. # member expansion on variables, variable name expansion and parameter completion
  950. # on commands. It doesn't understand strings so strings containing ; | ( or { may
  951. # cause expansion to fail.
  952.  
  953. param($line, $lastWord)
  954.  
  955. & {
  956. # Helper function to write out the matching set of members. It depends
  957. # on dynamic scoping to get $_base, _$expression and $_pat
  958. function Write-Members ($sep='.')
  959. {
  960. # evaluate the expression to get the object to examine...
  961. Invoke-Expression ('$_val=' + $_expression)
  962.  
  963. if ( $_expression -match '^\$global:_dummy' )
  964. {
  965. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  966. $_expression = '$_' + $temp
  967. }
  968.  
  969. $_method = [Management.Automation.PSMemberTypes] `
  970. 'Method,CodeMethod,ScriptMethod,ParameterizedProperty'
  971. if ($sep -eq '.')
  972. {
  973. $params = @{view = 'extended','adapted','base'}
  974. }
  975. else
  976. {
  977. $params = @{static=$true}
  978. }
  979.  
  980. if ( $_val -is [Hashtable] )
  981. {
  982. [Object[]]$_keys = $null
  983. foreach ( $_name in $_val.Keys )
  984. {
  985. $_keys += `
  986. New-Object Microsoft.PowerShell.Commands.MemberDefinition `
  987. [int],$_name,"Property",0
  988. }
  989. }
  990.  
  991. if ( $_keys -ne $null )
  992. {
  993. $_members = [Object[]](Get-Member @params -InputObject $_val $_pat) + ($_keys | ? {$_.name -like $_pat})
  994. } else {
  995. $_members = (Get-Member @params -InputObject $_val $_pat)
  996. }
  997.  
  998. foreach ($_m in $_members | Sort-Object membertype,name)
  999. {
  1000. if ($_m.MemberType -band $_method)
  1001. {
  1002. # Return a method...
  1003. $_base + $_expression + $sep + $_m.name + '('
  1004. }
  1005. else {
  1006. # Return a property...
  1007. $_base + $_expression + $sep + $_m.name
  1008. }
  1009. }
  1010. }
  1011. $host.UI.RawUI.WindowTitle = "Windows PowerShell V2 (CTP2)" + $lastword
  1012.  
  1013. switch ([int]$line[-1])
  1014. {
  1015. # Ctrl+D several date/time formats
  1016. 4 {
  1017. "[DateTime]::Now"
  1018. [DateTime]::Now
  1019. [DateTime]::Now.ToString("yyyyMMdd")
  1020. [DateTime]::Now.ToString("MMddyyyy")
  1021. [DateTime]::Now.ToString("yyyyMMddHHmmss")
  1022. [DateTime]::Now.ToString("MMddyyyyHHmmss")
  1023. 'd f g m o r t u y'.Split(" ") | % { [DateTime]::Now.ToString($_) }
  1024. break;
  1025. }
  1026.  
  1027. # Ctrl+P hand-operated pop from command buffer stack
  1028. 16 {
  1029. $_base = $lastword.SubString(0, $lastword.Length-1)
  1030. $_base + $global:_cmdstack.Pop()
  1031. break;
  1032. }
  1033.  
  1034. # Ctrl+R $Host.UI.RawUI.
  1035. 18 {
  1036. '$Host.UI.RawUI.'
  1037. '$Host.UI.RawUI'
  1038. break;
  1039. }
  1040.  
  1041. # Ctrl+V paste clipboard
  1042. 22 {
  1043. $_base = $lastword.SubString(0, $lastword.Length-1)
  1044. $global:_clip = New-Object System.Windows.Forms.TextBox
  1045. $global:_clip.Multiline = $true
  1046. $global:_clip.Paste()
  1047. $_base + $global:_clip.Text
  1048. break;
  1049. }
  1050. }
  1051.  
  1052.  
  1053. switch -regex ($lastWord)
  1054. {
  1055. # Handle property and method expansion at '$_'
  1056. '(^.*)(\$_\.)(\w*)$' {
  1057. $_base = $matches[1]
  1058. $_expression = '$global:_dummy'
  1059. $_pat = $matches[3] + '*'
  1060. $global:_dummy = $null
  1061. Get-PipeLineObject
  1062. if ( $global:_dummy -eq $null )
  1063. {
  1064. if ( $global:_exp -match '^\$.*\(.*$' )
  1065. {
  1066. $type = ( iex $global:_exp.Split("(")[0] ).OverloadDefinitions[0].Split(" ")[0] -replace '\[[^\[\]]*\]$' -as [type]
  1067.  
  1068. if ( $_expression -match '^\$global:_dummy' )
  1069. {
  1070. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1071. $_expression = '$_' + $temp
  1072. }
  1073.  
  1074. foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1075. {
  1076. if ($_m.MemberType -eq "Method")
  1077. {
  1078. $_base + $_expression + '.' + $_m.name + '('
  1079. }
  1080. else {
  1081. $_base + $_expression + '.' + $_m.name
  1082. }
  1083. }
  1084. break;
  1085. }
  1086. elseif ( $global:_exp -match '^\[.*\:\:.*\(.*$' )
  1087. {
  1088. $tname, $mname = $_exp.Split(":(", "RemoveEmptyEntries"-as [System.StringSplitOptions])[0,1]
  1089. $type = @(iex ($tname + '.GetMember("' + $mname + '")'))[0].ReturnType.FullName -replace '\[[^\[\]]*\]$' -as [type]
  1090.  
  1091. if ( $_expression -match '^\$global:_dummy' )
  1092. {
  1093. $temp = $_expression -replace '^\$global:_dummy(.*)','$1'
  1094. $_expression = '$_' + $temp
  1095. }
  1096.  
  1097. foreach ( $_m in $type.GetMembers() | sort membertype,name | group name | ? { $_.Name -like $_pat } | % { $_.Group[0] } )
  1098. {
  1099. if ($_m.MemberType -eq "Method")
  1100. {
  1101. $_base + $_expression + '.' + $_m.name + '('
  1102. }
  1103. else {
  1104. $_base + $_expression + '.' + $_m.name
  1105. }
  1106. }
  1107. break;
  1108. }
  1109. elseif ( $global:_exp -match '^(\$\w+(\[[0-9,\.]+\])*(\.\w+(\[[0-9,\.]+\])*)*)$' )
  1110. {
  1111. $global:_dummy = @(iex $Matches[1])[0]
  1112. }
  1113. else
  1114. {
  1115. $global:_dummy =  $global:_mix
  1116. }
  1117. }
  1118.  
  1119. Write-Members
  1120. break;
  1121. }
  1122.  
  1123. # Handle property and method expansion rooted at variables...
  1124. # e.g. $a.b.<tab>
  1125. '(^.*)(\$(\w|\.)+)\.(\w*)$' {
  1126. $_base = $matches[1]
  1127. $_expression = $matches[2]
  1128. $_pat = $matches[4] + '*'
  1129. [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1130. if ( $_expression -match '^\$_\.' )
  1131. {
  1132. $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1133. }
  1134. Write-Members
  1135. break;
  1136. }
  1137.  
  1138. # Handle simple property and method expansion on static members...
  1139. # e.g. [datetime]::n<tab>
  1140. '(^.*)(\[(\w|\.)+\])\:\:(\w*)$' {
  1141. $_base = $matches[1]
  1142. $_expression = $matches[2]
  1143. $_pat = $matches[4] + '*'
  1144. Write-Members '::'
  1145. break;
  1146. }
  1147.  
  1148. # Handle complex property and method expansion on static members
  1149. # where there are intermediate properties...
  1150. # e.g. [datetime]::now.d<tab>
  1151. '(^.*)(\[(\w|\.)+\]\:\:(\w+\.)+)(\w*)$' {
  1152. $_base = $matches[1]  # everything before the expression
  1153. $_expression = $matches[2].TrimEnd('.') # expression less trailing '.'
  1154. $_pat = $matches[5] + '*'  # the member to look for...
  1155. Write-Members
  1156. break;
  1157. }
  1158.  
  1159. # Handle variable name expansion...
  1160. '(^.*\$)(\w+)$' {
  1161. $_prefix = $matches[1]
  1162. $_varName = $matches[2]
  1163. foreach ($_v in Get-ChildItem ('variable:' + $_varName + '*'))
  1164. {
  1165. $_prefix + $_v.name
  1166. }
  1167. break;
  1168. }
  1169.  
  1170. # Handle env&function drives variable name expansion...
  1171. '(^.*\$)(.*\:)(\w+)$' {
  1172. $_prefix = $matches[1]
  1173. $_drive = $matches[2]
  1174. $_varName = $matches[3]
  1175. if ($_drive -eq "env:" -or $_drive -eq "function:")
  1176. {
  1177. foreach ($_v in Get-ChildItem ($_drive + $_varName + '*'))
  1178. {
  1179. $_prefix + $_drive + $_v.name
  1180. }
  1181. }
  1182. break;
  1183. }
  1184.  
  1185. # Handle array's element property and method expansion
  1186. # where there are intermediate properties...
  1187. # e.g. foo[0].n.b<tab>
  1188. '(^.*)(\$((\w+\.)|(\w+(\[(\w|,)+\])+\.))+)(\w*)$'
  1189. {
  1190. $_base = $matches[1]
  1191. $_expression = $matches[2].TrimEnd('.')
  1192. $_pat = $Matches[8] + '*'
  1193. [void] ( iex "$_expression.IsDataLanguageOnly" ) # for [ScriptBlock]
  1194. if ( $_expression -match '^\$_\.' )
  1195. {
  1196. $_expression = $_expression -replace '^\$_(.*)',('$global:_dummy' + '$1')
  1197. }
  1198. Write-Members
  1199. break;
  1200. }
  1201.  
  1202. # Handle property and method expansion rooted at type object...
  1203. # e.g. [System.Type].a<tab>
  1204. '(^\[(\w|\.)+\])\.(\w*)$'
  1205. {
  1206. if ( $(iex $Matches[1]) -isnot [System.Type] ) { break; }
  1207. $_expression = $Matches[1]
  1208. $_pat = $Matches[$matches.Count-1] + '*'
  1209. Write-Members
  1210. break;
  1211. }
  1212.  
  1213. # Handle complex property and method expansion on type object members
  1214. # where there are intermediate properties...
  1215. # e.g. [datetime].Assembly.a<tab>
  1216. '^(\[(\w|\.)+\]\.(\w+\.)+)(\w*)$' {
  1217. $_expression = $matches[1].TrimEnd('.') # expression less trailing '.'
  1218. $_pat = $matches[4] + '*'  # the member to look for...
  1219. if ( $(iex $_expression) -eq $null ) { break; }
  1220. Write-Members
  1221. break;
  1222. }
  1223.  
  1224. # Handle property and method expansion rooted at close parenthes...
  1225. # e.g. (123).a<tab>
  1226. '^(.*)\)((\w|\.)*)\.(\w*)$' {
  1227. $_base = $Matches[1] + ")"
  1228. if ( $matches[3] -eq $null) { $_expression = '[System.Type]' }
  1229. else { $_expression = '[System.Type]' + $Matches[2] }
  1230. $_pat = $matches[4] + '*'
  1231. iex "$_expression | Get-Member $_pat | sort MemberType,Name" |
  1232. % {
  1233. if ( $_.MemberType -like "*Method*" -or $_.MemberType -like "*Parameterized*" ) { $parenthes = "(" }
  1234. if ( $Matches[2] -eq "" ) { $_base + "." + $_.Name + $parenthes }
  1235. else { $_base + $Matches[2] + "." + $_.Name + $parenthes }
  1236. }
  1237. break;
  1238. }
  1239.  
  1240. # Handle .NET type name expansion ...
  1241. # e.g. [Microsoft.PowerShell.Com<tab>
  1242. '^\[(\w+(\.\w*)*)$' {
  1243. $_opt = $matches[1] + '*'
  1244. if ( $_opt -eq "*" )
  1245. {
  1246. $_TypeAccelerators -like $_opt -replace '^(.*)$', '[$1]'
  1247. }
  1248. else
  1249. {
  1250. $_TypeAccelerators -like $_opt -replace '^(.*)$', '[$1]'
  1251. "CmdletBinding", "Parameter", "Alias",
  1252. "ValidateArguments", "ValidateCount", "ValidateEnumeratedArguments", "ValidateLength",
  1253. "ValidateNotNull", "ValidateNotNullOrEmpty", "ValidatePattern", "ValidateRange",
  1254. "ValidateScript", "ValidateSet", "AllowEmptyCollection", "AllowEmptyString", "AllowNull" `
  1255. -like $_opt -replace '^(.*)$', '[$1('
  1256. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1) '['
  1257. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1) '['
  1258. }
  1259. break;
  1260. }
  1261.  
  1262. # Handle file/directory name which contains $env: variable
  1263. # e.g.  $env:windir\<tab>
  1264. '^\$(env:)?\w+([\\/][^\\/]*)*$' {
  1265. $path = iex ('"' + $Matches[0] + '"')
  1266. if ( $Matches[2].Length -gt 1 )
  1267. {
  1268. $parent = Split-Path $path -Parent
  1269. $leaf = (Split-Path $path -Leaf) + '*'
  1270. }
  1271. else
  1272. {
  1273. $parent = $path
  1274. $leaf = '*'
  1275. }
  1276. if ( Test-Path $parent )
  1277. {
  1278. $i = $Matches[0].LastIndexOfAny("/\")
  1279. $_base = $Matches[0].Substring(0,$i+1)
  1280. [IO.Directory]::GetFileSystemEntries( $parent, $leaf ) | % { $_base + ($_.Split("\/")[-1] -replace '([\$\s&])','`$1' -replace '([[\]])', '````$1') }
  1281. }
  1282. }
  1283.  
  1284. # Handle file glob expansion ...
  1285. # e.g. *.txt~about*@<tab>
  1286. '^(\^?([^~]+))(~(.*))*@$' {
  1287. if ( $Matches[1] -notlike "^*" )
  1288. {
  1289. $include = $Matches[2] -replace '``','`'
  1290. if ( $Matches[3] )
  1291. {
  1292. $exclude = $Matches[3].Split("~", "RemoveEmptyEntries" -as [System.StringSplitOptions]) -replace '``','`'
  1293. }
  1294. }
  1295. else
  1296. {
  1297. $include = "*"
  1298. $exclude = $Matches[2] -replace '``','`'
  1299. }
  1300. $fse = [IO.Directory]::GetFileSystemEntries($PWD)
  1301. $fse = $fse -replace '.*[\\/]([^/\\]*)$','$1'
  1302. % -in ($fse -like $include) { $fse = $_; $exclude | % { $fse = $fse -notlike $_ } }
  1303. $fse = $fse -replace '^.*\s.*$', ("'`$0'")
  1304. $fse = $fse -replace '([\[\]])', '``$1' -replace '^.*([\[\]]).*$', ("'`$0'")
  1305. $fse = $fse -replace "''", "'"
  1306. $OFS = ", "; "$fse"
  1307. $OFS = ", "; "* -Filter $include " + $(if($exclude){"-Exclude $exclude"})
  1308. $Matches[0].Substring(0, $Matches[0].Length-1)
  1309. break;
  1310. }
  1311.  
  1312. # Handle command buffer stack...
  1313. '(.*);(.?)$' {
  1314. $_base = $Matches[1]
  1315. if ( $Matches[2] -eq ":" -or $Matches[2] -eq "," )
  1316. {
  1317. if ( $_cmdstack.Count -gt 0 )
  1318. {
  1319. $_base + $global:_cmdstack.Pop()
  1320. }
  1321. else
  1322. {
  1323. ""; break;
  1324. }
  1325. }
  1326. elseif ( $Matches[2] -eq "" )
  1327. {
  1328. $global:_cmdstack.Push($line.SubString(0,$line.Length-1))
  1329. [System.Windows.Forms.SendKeys]::SendWait("{ESC}")
  1330. ""; break;
  1331. }
  1332. }
  1333.  
  1334. # Do completion on parameters...
  1335. '^-([\w0-9]*)' {
  1336. $_pat = $matches[1] + '*'
  1337.  
  1338. # extract the command name from the string
  1339. # first split the string into statements and pipeline elements
  1340. # This doesn't handle strings however.
  1341. $_command = [regex]::Split($line, '[|;=]')[-1]
  1342.  
  1343. #  Extract the trailing unclosed block e.g. ls | foreach { cp
  1344. if ($_command -match '\{([^\{\}]*)$')
  1345. {
  1346. $_command = $matches[1]
  1347. }
  1348.  
  1349. # Extract the longest unclosed parenthetical expression...
  1350. if ($_command -match '\(([^()]*)$')
  1351. {
  1352. $_command = $matches[1]
  1353. }
  1354.  
  1355. # take the first space separated token of the remaining string
  1356. # as the command to look up. Trim any leading or trailing spaces
  1357. # so you don't get leading empty elements.
  1358. $_command = $_command.Trim().Split()[0]
  1359.  
  1360. # now get the info object for it...
  1361. $_command = @(Get-Command -type 'All' $_command)[0]
  1362.  
  1363. # loop resolving aliases...
  1364. while ($_command.CommandType -eq 'alias')
  1365. {
  1366. $_command = @(Get-Command -type 'All' $_command.Definition)[0]
  1367. }
  1368.  
  1369. if ( $_command.name -eq "powershell.exe" )
  1370. {
  1371. if ( $global:_PSexeOption )
  1372. {
  1373. $global:_PSexeOption -like "-$_pat" -replace '^(-[^,]+).*$', '$1' | sort
  1374. }
  1375. else
  1376. {
  1377. ($global:_PSexeOption = powershell.exe -?) -like "-$_pat" -replace '^(-[^,]+).*$', '$1' | sort
  1378. }
  1379. break;
  1380. }
  1381.  
  1382.  
  1383. if ( $_command -ne $null )
  1384. {
  1385. # expand the parameter sets and emit the matching elements
  1386. foreach ($_n in $_command.Parameters.Keys | sort)
  1387. {
  1388. if ($_n -like $_pat) { '-' + $_n }
  1389. }
  1390. }
  1391. elseif ( $line -match 'switch\s+(-\w+\s+)*-(\w*)$')
  1392. {
  1393. $_pat = $Matches[2] + '*'
  1394. "regex", "wildcard", "exact", "casesensitive", "file" -like $_pat -replace '^(.*)$', '-$1'
  1395. break;
  1396. }
  1397. else
  1398. {
  1399. "-and", "-as", "-band", "-bnot", "-bor", "-bxor", "-ccontains", "-ceq", "-cge", "-cgt", "-cle", "-clike", "-clt",
  1400. "-cmatch", "-cne", "-cnotcontains", "-cnotlike", "-cnotmatch", "-contains", "-creplace", "-csplit", "-eq", "-f", "-ge",
  1401. "-gt", "-icontains", "-ieq", "-ige", "-igt", "-ile", "-ilike", "-ilt", "-imatch", "-ine", "-inotcontains", "-inotlike",
  1402. "-inotmatch", "-ireplace", "-is", "-isnot", "-isplit", "-join", "-le", "-like", "-lt", "-match", "-ne", "-not", "-notcontains",
  1403. "-notlike", "-notmatch", "-or", "-replace", "-split", "-xor" -like "-$_pat"
  1404. }
  1405. break;
  1406. }
  1407.  
  1408. # Tab complete against history either #<pattern> or #<id>
  1409. '^#(\w*)' {
  1410. $_pattern = $matches[1]
  1411. if ($_pattern -match '^[0-9]+$')
  1412. {
  1413. Get-History -ea SilentlyContinue -Id $_pattern | Foreach { $_.CommandLine }
  1414. }
  1415. else
  1416. {
  1417. $_pattern = '*' + $_pattern + '*'
  1418. Get-History | Sort-Object -Descending Id| Foreach { $_.CommandLine } | where { $_ -like $_pattern }
  1419. }
  1420. break;
  1421. }
  1422.  
  1423. # try to find a matching command...
  1424. default {
  1425.  
  1426. # parse the script...
  1427. $_tokens = [System.Management.Automation.PSParser]::Tokenize($line, [ref] $null)
  1428.  
  1429. if ( $_tokens )
  1430. {
  1431. $_lastToken = $_tokens[$_tokens.count - 1]
  1432. if ($_lastToken.Type -eq 'Member')
  1433. {
  1434. $_pat = $_lastToken.Content + '*'
  1435. $i=$_tokens.count; do { $i-- } until ( $_tokens[$i].Type -eq "Attribute")
  1436. if ( $lastWord -match "^(.*)([\(,])\w*$" )
  1437. {
  1438. $_base = $matches[1] + $matches[2]
  1439. }
  1440. switch ( $_tokens[$i].Content )
  1441. {
  1442. 'Parameter' {
  1443. [System.Management.Automation.ParameterAttribute].GetProperties() | ? { $_.Name -like $_pat -and $_.Name -ne "TypeId" } | % { $_base + $_.Name + "=" }
  1444. }
  1445. 'CmdletBinding' {
  1446. [System.Management.Automation.CmdletBindingAttribute].GetProperties() | ? { $_.Name -like $_pat -and $_.Name -ne "TypeId" } | % { $_base + $_.Name + "=" }
  1447. }
  1448. }
  1449. break;
  1450. }
  1451.  
  1452. if ( $_tokens[1].Type -eq "Attribute")
  1453. {
  1454. if ( $line.Split("(").Count -gt $line.Split(")").Count )
  1455. {
  1456. if ( $lastWord -match "^(.*)([\(,])\w*$" )
  1457. {
  1458. $_base = $matches[1] + $matches[2]
  1459. }
  1460. switch ( $_tokens[1].Content )
  1461. {
  1462. 'Parameter' {
  1463. [System.Management.Automation.ParameterAttribute].GetProperties() | % { $_base + $_.Name + "=" }
  1464. }
  1465. 'CmdletBinding' {
  1466. [System.Management.Automation.CmdletBindingAttribute].GetProperties()  | % { $_base + $_.Name + "=" }
  1467. }
  1468. }
  1469. }
  1470. break;
  1471. }
  1472. }
  1473.  
  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. {
  1507. $_method = $Matches[1]
  1508.  
  1509. if ( $Matches[3] -match "(.*)((`"|')(\w+,)+(\w*))$" )
  1510. {
  1511. $continuous = $true
  1512. $_opt =  $Matches[5] + '*'
  1513. $_base =  $Matches[2].TrimStart('"') -replace '(.*,)\w+$','$1'
  1514. $position = $Matches[1].Split(",").Length
  1515. }
  1516. else
  1517. {
  1518. $continuous = $false
  1519. $_opt = ($Matches[3].Split(',')[-1] -replace '^\s*','') + "*"
  1520. $position = $Matches[3].Split(",").Length
  1521. }
  1522.  
  1523. if ( ($_mdefs = iex ($_method + ".OverloadDefinitions")) -eq $null )
  1524. {
  1525. $tname, $mname = $_method.Split(":", "RemoveEmptyEntries" -as [System.StringSplitOptions])
  1526. $_mdefs = iex ($tname + '.GetMember("' + $mname + '") | % { $_.ToString() }')
  1527. }
  1528.  
  1529. foreach ( $def in $_mdefs )
  1530. {
  1531. [void] ($def -match '\((.*)\)')
  1532. foreach ( $param in [regex]::Split($Matches[1], ', ')[$position-1] )
  1533. {
  1534. if ($param -eq $null -or $param -eq "")
  1535. {
  1536. continue;
  1537. }
  1538. $type = $param.split()[0]
  1539.  
  1540. if ( $type -like '*`[*' -or $type -eq "Params" -or $type -eq "" )
  1541. {
  1542. continue;
  1543. }
  1544. $fullname  = @($_typenames -like "*$type*")
  1545. foreach ( $name in $fullname )
  1546. {
  1547. if ( $continuous -eq $true -and ( $name  -as [System.Type] ).IsEnum )
  1548. {
  1549. $output = [Enum]::GetValues($name) -like $_opt -replace '^(.*)$',($_base + '$1')
  1550. $output | sort
  1551. }
  1552. elseif ( ( $name  -as [System.Type] ).IsEnum )
  1553. {
  1554. $global:_enum = $name
  1555. $output = [Enum]::GetValues($name) -like $_opt -replace '^(.*)$','"$1"'
  1556. $output | sort
  1557. }
  1558. }
  1559. }
  1560. }
  1561. if ( $output -ne $null )
  1562. {
  1563. break;
  1564. }
  1565. }
  1566.  
  1567. if ( $line -match '(function|filter)\s+(\w*)$')
  1568. {
  1569. $_pat = 'function:\' + $Matches[2] + '*'
  1570. Get-ChildItem $_pat| % { $_.Name }
  1571. break;
  1572. }
  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 )
  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 | gm -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.  
  1689. if ( $line[-1] -eq " " )
  1690. {
  1691. # extract the command name from the string
  1692. # first split the string into statements and pipeline elements
  1693. # This doesn't handle strings however.
  1694. $_cmdlet = [regex]::Split($line, '[|;=]')[-1]
  1695.  
  1696. #  Extract the trailing unclosed block e.g. ls | foreach { cp
  1697. if ($_cmdlet -match '\{([^\{\}]*)$')
  1698. {
  1699. $_cmdlet = $matches[1]
  1700. }
  1701.  
  1702. # Extract the longest unclosed parenthetical expression...
  1703. if ($_cmdlet -match '\(([^()]*)$')
  1704. {
  1705. $_cmdlet = $matches[1]
  1706. }
  1707.  
  1708. # take the first space separated token of the remaining string
  1709. # as the command to look up. Trim any leading or trailing spaces
  1710. # so you don't get leading empty elements.
  1711. $_cmdlet = $_cmdlet.Trim().Split()[0]
  1712.  
  1713. # now get the info object for it...
  1714. $_cmdlet = @(Get-Command -type 'Application' $_cmdlet)[0]
  1715.  
  1716. if ( $_cmdlet.Name -eq "powershell.exe" )
  1717. {
  1718. "-PSConsoleFile", "-Version", "-NoLogo", "-NoExit", "-Sta", "-NoProfile", "-NonInteractive",
  1719. "-InputFormat", "-OutputFormat", "-EncodedCommand", "-File", "-Command" | sort
  1720. break;
  1721. }
  1722. if ( $_cmdlet.Name -eq "fsutil.exe" )
  1723. {
  1724. "behavior query", "behavior set", "dirty query", "dirty set",
  1725. "file findbysid", "file queryallocranges", "file setshortname", "file setvaliddata", "file setzerodata", "file createnew",
  1726. "fsinfo drives", "fsinfo drivetype", "fsinfo volumeinfo", "fsinfo ntfsinfo", "fsinfo statistics",
  1727. "hardlink create", "objectid query", "objectid set", "objectid delete", "objectid create",
  1728. "quota disable", "quota track", "quota enforce", "quota violations", "quota modify", "quota query",
  1729. "reparsepoint query", "reparsepoint delete", "sparse setflag", "sparse queryflag", "sparse queryrange", "sparse setrange",
  1730. "usn createjournal", "usn deletejournal", "usn enumdata", "usn queryjournal", "usn readdata", "volume dismount", "volume diskfree" | sort
  1731. break;
  1732. }
  1733. if ( $_cmdlet.Name -eq "net.exe" )
  1734. {
  1735. "ACCOUNTS ", " COMPUTER ", " CONFIG ", " CONTINUE ", " FILE ", " GROUP ", " HELP ",
  1736. "HELPMSG ", " LOCALGROUP ", " NAME ", " PAUSE ", " PRINT ", " SEND ", " SESSION ",
  1737. "SHARE ", " START ", " STATISTICS ", " STOP ", " TIME ", " USE ", " USER ", " VIEW" | sort
  1738. break;
  1739. }
  1740. if ( $_cmdlet.Name -eq "ipconfig.exe" )
  1741. {
  1742. "/?", "/all", "/renew", "/release", "/flushdns", "/displaydns",
  1743. "/registerdns", "/showclassid", "/setclassid"
  1744. break;
  1745. }
  1746. }
  1747.  
  1748. if ( $line -match '\w+\s+(\w+(\.|[^\s\.])*)$' )
  1749. {
  1750. #$_opt = $Matches[1] + '*'
  1751. $_cmdlet = $line.TrimEnd(" ").Split(" |(;={")[-2]
  1752.  
  1753. $_opt = $Matches[1].Split(" ,")[-1] + '*'
  1754. $_base = $Matches[1].Substring(0,$Matches[1].Length-$Matches[1].Split(" ,")[-1].length)
  1755.  
  1756.  
  1757. # now get the info object for it...
  1758. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet)[0]
  1759.  
  1760. # loop resolving aliases...
  1761. while ($_cmdlet.CommandType -eq 'alias')
  1762. {
  1763. $_cmdlet = @(Get-Command -type 'cmdlet,alias,function' $_cmdlet.Definition)[0]
  1764. }
  1765.  
  1766. if ( "Set-ExecutionPolicy" -eq $_cmdlet.Name )
  1767. {
  1768. "Unrestricted", "RemoteSigned", "AllSigned", "Restricted", "Default" -like $_opt | sort
  1769. break;
  1770. }
  1771.  
  1772. if ( "Trace-Command","Get-TraceSource","Set-TraceSource" -contains $_cmdlet.Name )
  1773. {
  1774. Get-TraceSource -Name $_opt | % { $_.Name } | sort -Unique | % { $_base + ($_ -replace '\s','` ') }
  1775. break;
  1776. }
  1777.  
  1778. if ( "New-Object" -eq $_cmdlet.Name )
  1779. {
  1780. $_TypeAccelerators -like $_opt
  1781. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1)
  1782. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1)
  1783. break;
  1784. }
  1785.  
  1786. if ( $_cmdlet.Name -like "*WMI*" )
  1787. {
  1788. Write-ClassNames $_WMIClasses ($_opt.Split("_").Count-1) -sep '_'
  1789. break;
  1790. }
  1791.  
  1792. if ( "Get-Process" -eq $_cmdlet.Name )
  1793. {
  1794. Get-Process $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1795. break;
  1796. }
  1797.  
  1798. if ( "Add-PSSnapin", "Get-PSSnapin", "Remove-PSSnapin" -contains $_cmdlet.Name )
  1799. {
  1800. if ( $global:_snapin -ne $null )
  1801. {
  1802. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  1803. break;
  1804. }
  1805. else
  1806. {
  1807. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  1808. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  1809. break;
  1810. }
  1811. }
  1812.  
  1813. if ( "Get-PSDrive", "New-PSDrive", "Remove-PSDrive" `
  1814. -contains $_cmdlet.Name -and "Name" )
  1815. {
  1816. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  1817. break;
  1818. }
  1819.  
  1820. if ( "Get-PSProvider" -eq $_cmdlet.Name )
  1821. {
  1822. Get-PSProvider -PSProvider $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1823. break;
  1824. }
  1825.  
  1826.  
  1827. if ( "Get-Eventlog" -eq $_cmdlet.Name )
  1828. {
  1829. Get-EventLog -List | ? { $_.Log -like $_opt } | % { $_base + ($_.Log -replace '\s','` ') }
  1830. break;
  1831. }
  1832.  
  1833. if ( "Get-Help" -eq $_cmdlet.Name -or "help" -eq $_cmdlet.Name )
  1834. {
  1835. Get-Help -Category all -Name $_opt | % { $_.Name } | sort -Unique
  1836. break;
  1837. }
  1838.  
  1839. if ( "Get-Service", "Restart-Service", "Resume-Service",
  1840. "Start-Service", "Stop-Service", "Suspend-Service" `
  1841. -contains $_cmdlet.Name )
  1842. {
  1843. Get-Service -Name $_opt | sort Name  | % { $_base + ($_.Name -replace '\s','` ') }
  1844. break;
  1845. }
  1846.  
  1847. if ( "Get-Command" -eq $_cmdlet.Name )
  1848. {
  1849. Get-Command -CommandType All -Name $_opt | % { $_base + ($_.Name -replace '\s','` ') }
  1850. break;
  1851. }
  1852.  
  1853. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Compare-Object",
  1854. "ConvertTo-Html", "Measure-Object", "Select-Object", "Group-Object", "Sort-Object" `
  1855. -contains $_cmdlet.Name )
  1856. {
  1857.  
  1858. Get-PipeLineObject
  1859. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  1860. break;
  1861. }
  1862.  
  1863. if ( "Clear-Variable", "Get-Variable", "New-Variable", "Remove-Variable", "Set-Variable" -contains $_cmdlet.Name )
  1864. {
  1865. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1866. break;
  1867. }
  1868.  
  1869. if ( "Get-Alias", "New-Alias", "Set-Alias" -contains $_cmdlet.Name )
  1870. {
  1871. Get-Alias -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1872. break;
  1873. }
  1874. }
  1875.  
  1876. if ( $line -match '(-(\w+))\s+([^-]*$)' )
  1877. {
  1878.  
  1879. $_param = $matches[2] + '*'
  1880. $_opt = $Matches[3].Split(" ,")[-1] + '*'
  1881. $_base = $Matches[3].Substring(0,$Matches[3].Length-$Matches[3].Split(" ,")[-1].length)
  1882. #$_opt = ($Matches[3] -replace '(^.*\s*,?\s*)\w*$','$1') + '*'
  1883.  
  1884. # extract the command name from the string
  1885. # first split the string into statements and pipeline elements
  1886. # This doesn't handle strings however.
  1887. $_cmdlet = [regex]::Split($line, '[|;=]')[-1]
  1888.  
  1889. #  Extract the trailing unclosed block e.g. ls | foreach { cp
  1890. if ($_cmdlet -match '\{([^\{\}]*)$')
  1891. {
  1892. $_cmdlet = $matches[1]
  1893. }
  1894.  
  1895. # Extract the longest unclosed parenthetical expression...
  1896. if ($_cmdlet -match '\(([^()]*)$')
  1897. {
  1898. $_cmdlet = $matches[1]
  1899. }
  1900.  
  1901. # take the first space separated token of the remaining string
  1902. # as the command to look up. Trim any leading or trailing spaces
  1903. # so you don't get leading empty elements.
  1904. $_cmdlet = $_cmdlet.Trim().Split()[0]
  1905.  
  1906. # now get the info object for it...
  1907. $_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet)[0]
  1908.  
  1909. # loop resolving aliases...
  1910. while ($_cmdlet.CommandType -eq 'alias')
  1911. {
  1912. $_cmdlet = @(Get-Command -type 'Cmdlet,Alias,Function,Filter,ExternalScript' $_cmdlet.Definition)[0]
  1913. }
  1914.  
  1915. if ( $_param.TrimEnd("*") -eq "ea" -or $_param.TrimEnd("*") -eq "wa" )
  1916. {
  1917. "SilentlyContinue", "Stop", "Continue", "Inquire" |
  1918. ? { $_ -like $_opt } | sort -Unique
  1919. break;
  1920. }
  1921.  
  1922. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide" -contains $_cmdlet.Name `
  1923. -and "groupBy" -like $_param )
  1924. {
  1925. Get-PipeLineObject
  1926. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_.Name }
  1927. break;
  1928. }
  1929.  
  1930. if ( $_param.TrimEnd("*") -eq "ev" -or $_param.TrimEnd("*") -eq "ov" -or
  1931. "ErrorVariable" -like $_param -or "OutVariable" -like $_param)
  1932. {
  1933. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort
  1934. break;
  1935. }
  1936.  
  1937. if ( "Tee-Object" -eq $_cmdlet.Name -and "Variable" -like $_param )
  1938. {
  1939. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort
  1940. break;
  1941. }
  1942.  
  1943. if ( "Clear-Variable", "Get-Variable", "New-Variable", "Remove-Variable", "Set-Variable" -contains $_cmdlet.Name `
  1944. -and "Name" -like $_param)
  1945. {
  1946. Get-Variable -Scope Global -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1947. break;
  1948. }
  1949.  
  1950. if ( "Export-Alias", "Get-Alias", "New-Alias", "Set-Alias" -contains $_cmdlet.Name `
  1951. -and "Name" -like $_param)
  1952. {
  1953. Get-Alias -Name $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  1954. break;
  1955. }
  1956.  
  1957. if ( "Out-File","Export-CSV","Select-String","Export-Clixml" -contains $_cmdlet.Name `
  1958. -and "Encoding" -like $_param)
  1959. {
  1960. "Unicode",  "UTF7", "UTF8", "ASCII", "UTF32", "BigEndianUnicode", "Default", "OEM" |
  1961. ? { $_ -like $_opt } | sort -Unique
  1962. break;
  1963. }
  1964.  
  1965. if ( "Trace-Command","Get-TraceSource","Set-TraceSource" -contains $_cmdlet.Name `
  1966. -and "Name" -like $_param)
  1967. {
  1968. Get-TraceSource -Name $_opt | % { $_.Name } | sort -Unique | % { $_base + ($_ -replace '\s','` ') }
  1969. break;
  1970. }
  1971.  
  1972. if ( "New-Object" -like $_cmdlet.Name )
  1973. {
  1974. if ( "ComObject" -like $_param )
  1975. {
  1976. $_ProgID -like $_opt | % { $_ -replace '\s','` ' }
  1977. break;
  1978. }
  1979.  
  1980. if ( "TypeName" -like $_param )
  1981. {
  1982. if ( $_opt -eq "*" )
  1983. {
  1984. $_TypeAccelerators -like $_opt
  1985. }
  1986. else
  1987. {
  1988. $_TypeAccelerators -like $_opt
  1989. Write-ClassNames $_TypeNames_System ($_opt.Split(".").Count-1)
  1990. Write-ClassNames $_TypeNames ($_opt.Split(".").Count-1)
  1991. }
  1992. break;
  1993. }
  1994. }
  1995.  
  1996. if ( "New-Item" -eq $_cmdlet.Name )
  1997. {
  1998. if ( "ItemType" -like $_param )
  1999. {
  2000. "directory", "file" -like $_opt
  2001. break;
  2002. }
  2003. }
  2004.  
  2005. if ( "Get-Location", "Get-PSDrive", "Get-PSProvider", "New-PSDrive", "Remove-PSDrive" `
  2006. -contains $_cmdlet.Name `
  2007. -and "PSProvider" -like $_param )
  2008. {
  2009. Get-PSProvider -PSProvider $_opt | % { $_.Name } | sort  | % { $_base + ($_ -replace '\s','` ') }
  2010. break;
  2011. }
  2012.  
  2013. if ( "Get-Location" -eq $_cmdlet.Name -and "PSDrive" -like $_param )
  2014. {
  2015. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  2016. break;
  2017. }
  2018.  
  2019. if ( "Get-PSDrive", "New-PSDrive", "Remove-PSDrive" `
  2020. -contains $_cmdlet.Name -and "Name" -like $_param )
  2021. {
  2022. Get-PSDrive -Name $_opt | sort | % { $_base + ($_ -replace '\s','` ') }
  2023. break;
  2024. }
  2025.  
  2026. if ( "Get-Command" -eq $_cmdlet.Name -and  "PSSnapin" -like $_param)
  2027. {
  2028. if ( $global:_snapin -ne $null )
  2029. {
  2030. $global:_snapin -like $_opt  | % { $_base + $_ }
  2031. break;
  2032. }
  2033. else
  2034. {
  2035. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  2036. $global:_snapin -like $_opt  | % { $_base + ($_ -replace '\s','` ') }
  2037. break;
  2038. }
  2039. }
  2040.  
  2041. if ( "Add-PSSnapin", "Get-PSSnapin", "Remove-PSSnapin" `
  2042. -contains $_cmdlet.Name -and "Name" -like $_param )
  2043. {
  2044. if ( $global:_snapin -ne $null )
  2045. {
  2046. $global:_snapin -like $_opt | % { $_base + ($_ -replace '\s','` ') }
  2047. break;
  2048. }
  2049. else
  2050. {
  2051. $global:_snapin = $(Get-PSSnapIn -Registered;Get-PSSnapIn)| sort Name -Unique;
  2052. $global:_snapin -like $_opt | % { $_base + $_ }
  2053. break;
  2054. }
  2055. }
  2056.  
  2057. if ( "Clear-Variable", "Export-Alias", "Get-Alias", "Get-PSDrive", "Get-Variable", "Import-Alias",
  2058. "New-Alias", "New-PSDrive", "New-Variable", "Remove-Variable", "Set-Alias", "Set-Variable" `
  2059. -contains $_cmdlet.Name -and "Scope" -like $_param )
  2060. {
  2061. "Global", "Local", "Script" -like $_opt
  2062. break;
  2063. }
  2064.  
  2065. if ( "Get-Process", "Stop-Process", "Wait-Process" -contains $_cmdlet.Name -and "Name" -like $_param )
  2066. {
  2067. Get-Process $_opt | % { $_.Name } | sort | % { $_base + ($_ -replace '\s','` ') }
  2068. break;
  2069. }
  2070.  
  2071. if ( "Get-Eventlog" -eq $_cmdlet.Name -and "LogName" -like $_param )
  2072. {
  2073. Get-EventLog -List | ? { $_.Log -like $_opt } | % { $_base + ($_.Log -replace '\s','` ') }
  2074. break;
  2075. }
  2076.  
  2077. if ( "Get-Help" -eq $_cmdlet.Name -or "help" -eq $_cmdlet.Name )
  2078. {
  2079. if ( "Name" -like $_param )
  2080. {
  2081. Get-Help -Category all -Name $_opt | % { $_.Name } | sort -Unique
  2082. break;
  2083. }
  2084. if ( "Category" -like $_param )
  2085. {
  2086. "Alias", "Cmdlet", "Provider", "General", "FAQ",
  2087. "Glossary", "HelpFile", "All" -like $_opt | sort | % { $_base + $_ }
  2088. break;
  2089. }
  2090. }
  2091.  
  2092. if ( "Get-Service", "Restart-Service", "Resume-Service",
  2093. "Start-Service", "Stop-Service", "Suspend-Service" `
  2094. -contains $_cmdlet.Name )
  2095. {
  2096. if ( "Name" -like $_param )
  2097. {
  2098. Get-Service -Name $_opt | sort Name  | % { $_base + ($_.Name -replace '\s','` ') }
  2099. break;
  2100. }
  2101. if ( "DisplayName" -like $_param )
  2102. {
  2103. Get-Service -Name $_opt | sort DisplayName | % { $_base + ($_.DisplayName -replace '\s','` ') }
  2104. break;
  2105. }
  2106. }
  2107.  
  2108. if ( "New-Service" -eq $_cmdlet.Name -and "dependsOn" -like $_param )
  2109. {
  2110. Get-Service -Name $_opt | sort Name | % { $_base + ($_.Name -replace '\s','` ') }
  2111. break;
  2112. }
  2113.  
  2114. if ( "Get-EventLog" -eq $_cmdlet.Name -and "EntryType" -like $_param )
  2115. {
  2116. "Error", "Information", "FailureAudit", "SuccessAudit", "Warning" -like $_opt | sort | % { $_base + $_ }
  2117. break;
  2118. }
  2119.  
  2120. if ( "Get-Command" -eq $_cmdlet.Name -and "Name" -like $_param )
  2121. {
  2122. Get-Command -CommandType All -Name $_opt | % { $_base + ($_.Name -replace '\s','` ') }
  2123. break;
  2124. }
  2125.  
  2126. if ( $_cmdlet.Noun -like "*WMI*" )
  2127. {
  2128. if ( "Class" -like $_param )
  2129. {
  2130. Write-ClassNames $_WMIClasses ($_opt.Split("_").Count-1) -sep '_'
  2131. break;
  2132. }
  2133. }
  2134.  
  2135. if ( "Format-List", "Format-Custom", "Format-Table", "Format-Wide", "Compare-Object",
  2136. "ConvertTo-Html", "Measure-Object", "Select-Object", "Group-Object", "Sort-Object" `
  2137. -contains $_cmdlet.Name -and "Property" -like $_param )
  2138. {
  2139. Get-PipeLineObject
  2140. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  2141. break;
  2142. }
  2143.  
  2144. if ( "Select-Object" -eq $_cmdlet.Name )
  2145. {
  2146. if ( "ExcludeProperty" -like $_param )
  2147. {
  2148. Get-PipeLineObject
  2149. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_base + ($_.Name -replace '\s','` ') }
  2150. break;
  2151. }
  2152.  
  2153. if ( "ExpandProperty" -like $_param )
  2154. {
  2155. Get-PipeLineObject
  2156. $_dummy | Get-Member -Name $_opt -MemberType Properties,ParameterizedProperty | sort membertype | % { $_.Name }
  2157. break;
  2158. }
  2159. }
  2160.  
  2161. select -InputObject $_cmdlet -ExpandProperty ParameterSets | select -ExpandProperty Parameters |
  2162. ? { $_.Name -like $_param } | ? { $_.ParameterType.IsEnum } |
  2163. % { [Enum]::GetNames($_.ParameterType) } | ? { $_ -like $_opt } | sort -Unique | % { $_base + $_ }
  2164.  
  2165. }
  2166.  
  2167. if ($_tokens)
  2168. {
  2169. $_lastToken = $_tokens[$_tokens.count - 1]
  2170. if ($_lastToken.Type -eq 'Command')
  2171. {
  2172. $_cmd = $_lastToken.Content
  2173.  
  2174. # don't look for paths...
  2175. if ($_cmd.IndexOfAny('/\') -eq -1)
  2176. {
  2177. # handle parsing errors - the last token string should be the last
  2178. # string in the line...
  2179. if ($lastword.substring($lastword.length-$_cmd.length) -eq $_cmd)
  2180. {
  2181. $_pat = $_cmd + '*'
  2182. $_base = $lastword.substring(0, $lastword.length-$_cmd.length)
  2183. "begin {", "break", "catch {", "continue", "data {", "do {", "dynamicparam (", "else {", "elseif (",
  2184. "end {", "exit", "filter ", "finally {", "for (", "foreach ", "from", "function ", "if (", "in ",
  2185. "param (", "process {", "return", "switch ", "throw ", "trap ", "try {", "until (", "while (" `
  2186. -like $_pat | %  {'{0}{1}' -f $_base,$_ }
  2187. $ExecutionContext.InvokeCommand.GetCommandName($_pat,$true, $false) |
  2188. Sort-Object -Unique | ForEach-Object {'{0}{1}' -f $_base,$_ }
  2189. }
  2190. }
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196. }

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