Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

I updated the PowerTab, PowerShell TabExpansion function and library,

the new version is PowerTab 0.8 and can be downloaded from the  PowerTab Overview Page

In this new version the following changes are made :

As no one did answer the Reader question I added the textbased version myself :

get-help about_[tab]

get-help about_Alias

I addition the following Changes are made (Some I explain in a bit more detail later in this post )

  • () method and property expansion improved
  • Red progressBar and Sleep  are gone ( Sorry added that for MCT summit demo and forgot to remove )
  • Get-TabExpansionCustom and Get-TabExpansionComputer added
  • Tabcompletion GUI DataBase editor added (Edit-TabExpansion)
  • CmdLet Function and Alias expansion realtime (not in database) by default, so no refresh needed
  • Computer and Share tabcompletion added
  • Computer import from AD OU or "Net View" helper functions
  • save-TabExpansion and load-TabExpansion  take filename parameter now

 

() method and property expansion improved (MutliLevel and not only beginning of line )

Expansion on () blocks that contain spaces not only works at beginning of line anymore, but also after | or ; and it works multi-level now :

( ls *.ps1 ).C[tab].t[tab]

PoSH> "number of PS1 files : " ; ( ls *.ps1 ).Count                                                                                         
number of PS1 files :                                                                                                                       
29                                                                                                                                          
PoSH> 1..3 |% { ( ls *.ps1 ).Count.toString() }                                                                                                        
29                                                                                                                                          
29                                                                                                                                          
29                                                                                                                                          
PoSH>                                                                      

 

  • Get-TabExpansionCustom and Get-TabExpansionComputer added

    So you can quickly see what your custom defined aliases and computerlist (new) are

    PoSH> get-TabExpansionComputer                                                                                                              
    Current Custom Computerlist :                                                                                                               
                                                                                                                                                
    Filter    Text      Type                                                                                                                    
    ------    ----      ----                                                                                                                    
    Localhost Localhost Computer                                                                                                                
                                                                                                                                                
                                                                                                                                                
    PoSH> get-TabExpansionCustom                                                                                                                
    Current Custom Aliases :                                                                                                                    
                                                                                                                                                
    Filter Text                                                  Type                                                                           
    ------ ----                                                  ----                                                                           
    tqb    "The Quick Brown Fox Jumps over the lazy dog"         Custom                                                                         
    |%     | Foreach-Object {$_}                                 Custom                                                                         
    |?     | Where {$_}                                          Custom                                                                         
    cc     @{Name=';Expression={$_}}                             Custom                                                                         
    gb     get-buffer | out-file C:\PowerShell\PowerTab\Examples Custom                                                                         
    ate    Add-Tabexpansion                                      Custom                                                                         
    rte    Refresh-TabExpansion                                  Custom                                                                         
    gtcom  get-TabExpansionComputer                              Custom                                                                         
    gtc    get-TabExpansionCustom                                Custom                                                                         
                                                                                                                                                
                                                                                                                                                
    PoSH> edit-TabExpansionDatabase                                                                                                             
    Cancel                                                                                                                                      
    PoSH> Save-tabExpansion                                                                                                                     
    PoSH>                                                                 
    

     

  • Tabcompletion GUI DataBase editor added (Edit-TabExpansion)

    You can use this GUI editor to View, Change, Add and Delete record from the Database 

  •  

    Computer and Share tabcompletion added

  • \\L[tab]

  • \\Localhost\p[tab]

    PoSH> cd \\Localhost\posh                                                                                                                   
    PoSH> cd \\Localhost\c$                                                                                                                     
    PoSH>                                                                
    

     This is a nice one, Gusev Vasily, AKA Xaegr came with the idea for this, he did use "Net View", and did ask if I did know a "Cleaner" way, to get the shares ( and for me RmtShare.exe was to "legency" ;- )

    • First I came to WMI, but you have to be Administrator on the remote machine for that,
    • then I did try ADSI, but that did not show hidden shares and also has the admin problem

     

    And also this would not work on old (w95/w98) and  "Non windows" boxes (Linux, Samba )

     

  • But again (see :  PowerShell : Accessing alternative data-streams of files on an NTFS volume ... ) CodeProject.com came to the resque

  • again with a C# library I could load and use.

    http://www.codeproject.com/cs/internet/networkshares.asp

     

    As this library uses a Network API ... it works against almost everything !, really Cool ! (Tested on NAS and VMS Pathworks OK)

    so I loaded the DDL into PowerShell ( and did Update Installer to Add this in profile also )  

     

    ############# Start of PowerTab 0.8 TabCompletion Code ########################

    # For Loading of Custom TabExpansion, added by PowerTab 0.8 Setup
    # http://ThePowerShellGuy.com

    '$installDir\TabExpansion.ps1'        # Load Tabcompletion function
    '$installDir\TabExpansionLib.ps1'     # Utility Functions
    '$installDir\Out-DataGridView.ps1'    # Used for GUI TabExpansion

    Load-TabExpansion # Load the TabExpansion DataBase

    # load External Library for Share Enumeration

    [void][System.Reflection.Assembly]::LoadFile('$installDir\shares.dll')

    ############# End of PowerTab 0.8 TabCompletion Code #########################

     

    The Code in the TabExpansion.PS1 function looks like this (including WMI and ADSI methods ):

     you can see we use the GetShares() method of the [Trinet.Networking.ShareCollection] Object (we have tabcompletion on that also (refresh-TabExpansionTypes)

  •  

            '^\\\\([^\\]+)$' { 
                 $global:dsTabExpansion.Tables['Custom'].select("filter like '$($matches[1])%' AND type = 'Computer' ","text") |% {"\\$($_.text)"}
            } 

            '^\\\\([^\\]+)\\([^\\]*)$' { 
                 #gwmi win32_share -computer $matches[1] -filter "name like '$($matches[2])%'" | Foreach-Object {"\\$($matches[1])\$($_.name)"}
                 #([adsi]"WinNT://$($matches[1])/LanmanServer,FileService" ).psbase.children |? {$_.name -like "$($matches[2])*"}  |% {$_.name}
                 [Trinet.Networking.ShareCollection]::GetShares($matches[1]) |? {$_.netname -like "$($matches[2])*"} |% {"\\$($matches[1])\$($_.netname)"}
            } 

     

     This share enumeration is very powerfull, it even lists adminshares you do not have rights to (you can not access them ofcouse and get a not found message

  • You can see for the computer I use a database and I made 2 refresh functions :

     

    Function add-TabExpansionComputersNetView {
      net view |% {if($_ -match '\\\\(.*?) '){$matches[1]}} |% {add-tabExpansion $_ $_ 'Computer'}
    }

    Function add-TabExpansionComputersOU ([adsi]$ou){
      $Ou.psbase.get_children() | select @{e={$_.cn[0]};n='Name'} |% {add-tabExpansion $_.name $_.name 'Computer'}
    }

     

     So you can add computers from the Browserlist (net view) or from Active Directory

     also you can update them by using add-TabExpansion manual :

     

    PoSH> add-tabExpansion 'Server1' 'Server1' 'Computer'                                                                                       
                                                                                                                                                
    Filter                                         Text                                           Type                                          
    ------                                         ----                                           ----                                          
    Server1                                        Server1                                        Computer                                      
                                                                                                                                                
                                                                                                                                                
    PoSH> get-TabExpansionComputer                                                                                                              
    Current Custom Computerlist :                                                                                                               
                                                                                                                                                
    Filter    Text      Type                                                                                                                    
    ------    ----      ----                                                                                                                    
    Localhost Localhost Computer                                                                                                                
    Server1   Server1   Computer                                                                                                                
                                                                                                                                                
                                                                                                                                                
    PoSH>                                                             
    

     

    CmdLet Function and Alias expansion realtime (not in database) by default, so no refresh needed

    as I did think the resolving was quick enough I removed this from the database and do a lookup in real-time (old lines commented)

    so now we do not need to refresh after adding aliases or functions

  • save-TabExpansion and load-TabExpansion  take filename parameter now

    So you can make Backups before changing the DataBase and load different DataBases, TabExpansion.XML will be used by default

     

    PoSH> Save-tabExpansion TabExtensionbackup.xml                                                                                              
    PoSH> edit-TabExpansionDatabase                                                                                                             
    PoSH> Save-tabExpansion                                                                                                                     
    PoSH> load-tabExpansion TabExtensionbackup.xml                                                                                              
    PoSH>                                                                
    

    you can download this new 0.8 version here : PowerTab Overview Page 

  • ( * Upgrade note * If you upgrade from 0.7x manual remove the old Profile code and if you have custom aliases not overwrite the database)

    I also included the DLL I compliled and the sourcefiles of the Share library in the PowerTab.zip file

     *Extra tip*

  •  try $psHome\[tab]

    Enjoy,

    Greetings /\/\o\/\/

     

  • Published Monday, January 29, 2007 2:34 PM by admin

    Comments

    # The PowerShell Guy : PowerTab

    Monday, January 29, 2007 3:37 PM by The PowerShell Guy : PowerTab

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    Thanks! :) Cool update, so many improvements :)

    Monday, January 29, 2007 10:42 PM by Xaegr

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    Your welcome,

    thanks for the input

    gr /\/\o\/\/

    Tuesday, January 30, 2007 4:38 AM by MoW

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    Nice work

    Would be helpful if the add-TabExpansionComputersOU had a filter for objectclass equal to 'computer'

    Tuesday, January 30, 2007 6:45 AM by JonnyG

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    @ JonnyG,

    Yes, I did set up the scripts as examples, but it's easy to implement yourself, by using add-TabeExpansion.

    Some examples using the searcher  (pre RC2):

    http://mow001.blogspot.com/2005/12/get-ad-info-into-nested-hashtable-from.html

    http://mow001.blogspot.com/2006/03/working-with-csv-files-in-msh-part-one.html

    Greetings /\/\o\/\/

    Tuesday, January 30, 2007 7:19 AM by MoW

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    for example,

    this will add al the computers in the Computers OU and sub-OU's

    $ds = new-Object System.DirectoryServices.DirectorySearcher

    $ds.SearchRoot = "LDAP://OU=Computers,DC=thePowerShellGuy,DC=com"

    $ds.Filter = "objectClass=Computer"

    $ds.FindAll() |% {add-tabExpansion $_.properties.cn $_.properties.cn 'computer'}

    Greetings /\/\o\/\/

    Tuesday, January 30, 2007 7:32 AM by MoW

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    Your Tab Completion is absolutely amazing. Love it!  I was trying to figure out how to use Add-TabExpansion to expand services and process.

    for example, get-service [tab] and be able to tab through all the services.

    Like wise, get-process [tab] would cycle through all the running processes.

    I'd really appreciate your help!

    Regards,

    Andy Schneider

    andy@nodisabilities.com

    Friday, February 23, 2007 6:57 PM by Andy

    # PowerShell TabExtension - Part 5 PowerTab 0.9

    I made some mayor updates to my PowerShell TabExtension Function PowerTab , most important are DoubleClick

    Monday, April 16, 2007 4:44 PM by The PowerShell Guy

    # PowerShell TabExtension - Part 6 Customizing PowerTab 0.9

    I mentioned in last post about the new version of PowerTab PowerShell TabExtension - Part 5 PowerTab

    Wednesday, April 18, 2007 5:50 PM by The PowerShell Guy

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    No mention that it appears that edit-tabexpansion is now invoke-tabexpansioneditor.

    Sunday, June 17, 2007 9:39 PM by Marco Shaw

    # re: PowerTab 0.8 PowerShell TabExtension - Part 4 Updates from 0.72

    Monday, June 18, 2007 1:37 AM by MoW
    Anonymous comments are disabled