PoshCode Logo PowerShell Code Repository

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

The most needless, useless and worthless Tabexpansion for powershell.exe(v1.0) in PoshCode.
Please dot souce this script file to use.
Update:.

  1. WMI Namespaces expansion for Get-WmiObject
gwmi -Namespace <tab>. Get-WmiObject -Namespace root\asp<tab>.

  1. WMI Classes expansion which is corresponding to WMI Namespace (*)
gwmi -Namespace ROOT\CIMV2\ms_409 -Class <tab>_<tab>.

(*) it needs to remove old $PSHOME\WMIClasses.txt if it exists.

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

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