#Based on a PowerShell.com PowerTip #http://powershell.com/cs/blogs/tips/archive/2014/10/07/getting-a-variable-inventory.aspx #Add to script inside ISE #Kaplan changed function name, as Get-Variable already in use, #Gave unique name to function variables to exclude, added other system variables, #Added example to show current values with enumeration Function Get-ScriptVariables { $GetVar_Token= $null $GetVar_Errors = $null $GetVar_AST = [System.Management.Automation.Language.Parser]::ParseInput($psise.CurrentFile.Editor.Text, [ref] $GetVar_Token, [ref] $GetVar_Errors) # not complete, add variables you want to exclude from the list: $GetVar_SysVars = "_,null,psitem,psise,true,false,args,host".Split(",") $null = $GetVar_AST.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true) $GetVar_Token| Where-Object { $_.Kind -eq 'Variable'} | Select-Object -ExpandProperty Name | Where-Object { $GetVar_SysVars -notcontains $_ } | Where-Object { $_ -notlike "GetVar_*"} Sort-Object -Unique } #example variables $a=3 $b="jack" #end Get-ScriptVariables| ForEach-Object {Get-Variable $_} |ft -AutoSize