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\/\/