Most standard variables can be found in System.Management.Automation.SpecialVariables . If you filter them and a short list of other known variables, you can create a reusable function to get custom variables:
function Get-UDVariable { get-variable | where-object {(@( "FormatEnumerationLimit", "MaximumAliasCount", "MaximumDriveCount", "MaximumErrorCount", "MaximumFunctionCount", "MaximumVariableCount", "PGHome", "PGSE", "PGUICulture", "PGVersionTable", "PROFILE", "PSSessionOption" ) -notcontains $_.name) -and ` (([psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') | Where-Object FieldType -eq ([string]) | ForEach-Object GetValue $null)) -notcontains $_.name } } $a = 5 $b = 10 get-udvariable Name Value ---- ----- a 5 b 10
Note ISE has two additional standard variables: $ psISE and $ psUsupportedConsoleApplications
jon Z
source share