PoshCode Logo PowerShell Code Repository

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

The most needless, useless and worthless Tabexpansion for powershell.exe(v2.0CTP3) in PoshCode.
Update:

  1. Parameter name (and command alias) expansion with Ctrl+E
ls -f *.txt -r | ? { $_.LastWriteTime -lt “2009/5” } | Select-String powershell -e OEM<Ctrl+E><tab>.
<br> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt “2009/5” } | Select-String powershell -Exclude OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt “2009/5” } | Select-String powershell -Encoding OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt “2009/5” } | Select-String powershell -ErrorAction OEM<tab><tab>...

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

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