Get-World | ConvertTo-PowerShell
ISE: List variables in active Script Pane
I was working in ISE pretty much during last two days (oh yes, was nice end of 2011 and beginning of 2012). During script creation I was checking values of variables frequently. Wouldn’t be nice to see variables value and not just write it’s name to Command Pane? So I came with another menu Add-on command.
function GetValues { $content = $psISE.CurrentFile.Editor.Text $tokens = [System.Management.Automation.PsParser]::Tokenize($content, [ref] $null) |? {$_.Type -eq 'Variable'} | Sort Content -Unique foreach ($t in $tokens) { $prop = @{ Name = $t.Content Value = Get-Variable -Name $($t.Content) -ValueOnly -ErrorAction SilentlyContinue } New-Object -TypeName PSObject -Property $prop | Select Name, Value } } $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Show values',{GetValues},'CTRL+SHIFT+V') | Out-Null
When you work with any script, you can run it and will see all actual script variables in Output Pane.

Using Tokenizer API I received all variables from current script and created new object with variable name and value. Then it’s send to output. I am thinking about some graphical output (WPF or ShowUI) or just to Out-GridView. There are also some another points to update but for my current needs it’s OK.
| Print article | This entry was posted by makovec on 01/01/2012 at 18:21, and is filed under PowerShell. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
