Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Created February 28, 2019 18:15
Show Gist options
  • Save PrateekKumarSingh/9100d8115b39dd39818b69caf227cd57 to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/9100d8115b39dd39818b69caf227cd57 to your computer and use it in GitHub Desktop.
Function Get-Vars{
Write-Host "-------------------------------------------------------------------"
Write-Host "-------------------------------------------------------------------"
switch($host.Name){
'Visual Studio Code Host' {
$psEditor.GetEditorContext().CurrentFile.tokens.where({$_.kind -eq 'variable'}) | Select @{n='Name';e={$_.extent}},@{n='value';e={iex $($_.extent)}} -Unique
}
'Windows PowerShell ISE Host' {
$abstractSyntaxTree = [System.Management.Automation.Language.Parser]::ParseInput($psISE.CurrentFile.Editor.Text, [ref]$null, [ref]$null)
$AbstractSyntaxTree.FindAll({$args[0] -is [System.Management.Automation.Language.VariableExpressionAst ]}, $true) | Select @{n='Name';e={$_.extent}},@{n='value';e={iex $($_.extent)}} -Unique | ft -AutoSize
}
}
Write-Host "-------------------------------------------------------------------"
Write-Host "-------------------------------------------------------------------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment