Skip to content

Instantly share code, notes, and snippets.

@altrive
Created March 28, 2014 07:40
Show Gist options
  • Save altrive/9827349 to your computer and use it in GitHub Desktop.
Save altrive/9827349 to your computer and use it in GitHub Desktop.
function Get-LocalVariable
{
[CmdletBinding()]
param (
)
#define buildin variables
$builtinVariable = [PSObject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') | where FieldType -eq ([string]) | foreach GetValue($null)
$builtinVariable += @("FormatEnumerationLimit", "MaximumAliasCount", "MaximumDriveCount", "MaximumErrorCount", "MaximumFunctionCount", "MaximumHistoryCount", "MaximumVariableCount", "profile", "psISE", "PSSessionOption", "PSUICulture", "psUnsupportedConsoleApplications", "PSVersionTable", "startupFiles")
#Get local variable(If use this function inside PSModule, set -Scope 2 instead )
$variables = Get-Variable -Scope 1 | where Name -notin $builtinVariable | select Name,Value
return $variables
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment