tech.guitarrapc.cóm

Technical updates

PowerShell 3.0のBuild-In Variableを取得する

結構大事。 PowerShell V3.0でのやり方ですね。
Finding Built-In Variables
簡単に見ておきます。

変数の取得

現在の変数の取得には、コマンドレットが用意されています。
Get-Variable
あるいは、[PSDrive]のVariableで一覧取得もありですね。
Get-ChildItem variable:
ただ、これでは、ビルトイン変数とユーザー定義変数がごっちゃ混ぜになってしまいます。 Get-Variable | select *Get-ChildItem variable:では区別がつかないのでしょうか? つかないのです…。 例えば$aを定義します。
$a = 0
Built-In変数と見比べてみてください。
Get-Variable | select * | sort Name

#あるいは
Get-ChildItem variable: | select * | sort Name
どうでしょうか。
PSPath        : Microsoft.PowerShell.Core\Variable::a
PSDrive       : Variable
PSProvider    : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Name          : a
Description   :
Value         : 0
Visibility    : Public
Module        :
ModuleName    :
Options       : None
Attributes    : {}
PSPath        : Microsoft.PowerShell.Core\Variable::?
PSDrive       : Variable
PSProvider    : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Value         : True
Name          : ?
Description   : 最後のコマンドの実行状態。
Visibility    : Public
Module        :
ModuleName    :
Options       : ReadOnly, AllScope
Attributes    : {}

PSPath        : Microsoft.PowerShell.Core\Variable::^
PSDrive       : Variable
PSProvider    : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Name          : ^
Description   :
Value         : $a
Visibility    : Public
Module        :
ModuleName    :
Options       : None
Attributes    : {}

PSPath        : Microsoft.PowerShell.Core\Variable::ConsoleFileName
PSDrive       : Variable
PSProvider    : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Name          : ConsoleFileName
Description   : 現在のコンソール ファイルの名前。
Value         :
Visibility    : Public
Module        :
ModuleName    :
Options       : ReadOnly, AllScope
Attributes    : {}
そこで、今回の記事の内容が生きてきます。

ビルトイン変数のみを取得したい

ここに格納されています。
[psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static')
ただそのまま出してしまうと…ちょっと。
Name
----
HistorySizeVarPath
MyInvocationVarPath
OFSVarPath
OutputEncodingVarPath
VerboseHelpErrorsVarPath
LogEngineHealthEventVarPath
LogEngineLifecycleEventVarPath
LogCommandHealthEventVarPath
LogCommandLifecycleEventVarPath
LogProviderHealthEventVarPath
LogProviderLifecycleEventVarPath
LogSettingsEventVarPath
PSLogUserDataPath
NestedPromptCounterVarPath
CurrentlyExecutingCommandVarPath
PSBoundParametersVarPath
MatchesVarPath
LastExitCodeVarPath
PSDebugContextVarPath
StackTraceVarPath
FirstTokenVarPath
LastTokenVarPath
UnderbarVarPath
QuestionVarPath
ArgsVarPath
ThisVarPath
InputVarPath
PSCmdletVarPath
ErrorVarPath
EventErrorVarPath
PathExtVarPath
PSEmailServerVarPath
PSDefaultParameterValuesVarPath
PSScriptRootVarPath
PSCommandPathVarPath
foreachVarPath
switchVarPath
PWDVarPath
NullVarPath
TrueVarPath
FalseVarPath
PSModuleAutoLoadingPreferenceVarPath
DebugPreferenceVarPath
ErrorActionPreferenceVarPath
ProgressPreferenceVarPath
VerbosePreferenceVarPath
WarningPreferenceVarPath
WhatIfPreferenceVarPath
ConfirmPreferenceVarPath
ErrorViewVarPath
PSSessionConfigurationNameVarPath
PSSessionApplicationNameVarPath
AllScopeSessionVariables
AutomaticVariables
AutomaticVariableTypes
PreferenceVariables
PreferenceVariableTypes
AllScopeVariables
HistorySize
MyInvocation
OFS
OutputEncoding
VerboseHelpErrors
LogEngineHealthEvent
LogEngineLifecycleEvent
LogCommandHealthEvent
LogCommandLifecycleEvent
LogProviderHealthEvent
LogProviderLifecycleEvent
LogSettingsEvent
PSLogUserData
NestedPromptLevel
CurrentlyExecutingCommand
PSBoundParameters
Matches
LastExitCode
PSDebugContext
StackTrace
FirstToken
LastToken
PSItem
Underbar
Question
Args
This
Input
PSCmdlet
Error
EventError
PathExt
PSEmailServer
PSDefaultParameterValues
PSScriptRoot
PSCommandPath
foreach
switch
pwd
Null
True
False
PSModuleAutoLoading
DebugPreference
ErrorActionPreference
ProgressPreference
VerbosePreference
WarningPreference
WhatIfPreference
ConfirmPreference
ErrorView
PSSessionConfigurationName
PSSessionApplicationName
ConsoleFileName
ExecutionContext
Home
Host
PID
PSCulture
PSHome
PSUICulture
PSVersionTable
ShellId

型一覧の取得

まず、型を見てみましょう。
[psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') `
    | sort FieldType -Unique `
    | select FieldType
System.Collections.Generic.List`1[System.String]
System.Management.Automation.VariablePath
System.String
System.String[]
System.Type[]

型毎に変数の取得

型ごとの変数を見てみると…
$fieldType = $specialVariables `
    | sort FieldType -Unique

$fieldType `
    | %{
        $type = $_
        $specialVariables `
            | ?{$_.FieldType -eq (iex ("[" +$_.FieldType +"]"))} `
        | %{[PsCustomObject]@{userpath=$_.GetValue($null); type=$type}} `
        | sort userpath -Unique
    }
ちょっと出力がはみ出たので、調整しています。
$fieldType = $specialVariables `
    | sort FieldType -Unique

$fieldType `
    | %{
        $type = $_
        $specialVariables `
            | ?{$_.FieldType -eq (iex ("[" +$_.FieldType +"]"))} `
        | %{[PsCustomObject]@{
            userpath=$_.GetValue($null)
            type=$type.ToString().Substring(0,18)}} `
        | sort userpath -Unique
    }
userpath                                                                  type
--------                                                                  ----
$                                                                         System.Collections
?                                                                         System.Collections
{?, ConsoleFileName, ExecutionContext, false...}                          System.Collections
^                                                                         System.Collections
_                                                                         System.Collections
{_, args, this, input...}                                                 System.Collections
args                                                                      System.Collections
ConfirmPreference                                                         System.Collections
ConsoleFileName                                                           System.Collections
{ConsoleFileName, ExecutionContext, HOME, Host...}                        System.Collections
CurrentlyExecutingCommand                                                 System.Collections
DebugPreference                                                           System.Collections
{DebugPreference, VerbosePreference, ErrorActionPreference, WhatIfPref... System.Collections
env:PATHEXT                                                               System.Collections
error                                                                     System.Collections
ErrorActionPreference                                                     System.Collections
ErrorView                                                                 System.Collections
ExecutionContext                                                          System.Collections
false                                                                     System.Collections
foreach                                                                   System.Collections
global:$                                                                  System.Collections
global:^                                                                  System.Collections
global:error                                                              System.Collections
global:LASTEXITCODE                                                       System.Collections
global:NestedPromptLevel                                                  System.Collections
global:PSModuleAutoLoadingPreference                                      System.Collections
global:PSSessionApplicationName                                           System.Collections
global:PSSessionConfigurationName                                         System.Collections
global:PWD                                                                System.Collections
global:StackTrace                                                         System.Collections
HOME                                                                      System.Collections
Host                                                                      System.Collections
input                                                                     System.Collections
LASTEXITCODE                                                              System.Collections
local:args                                                                System.Collections
local:foreach                                                             System.Collections
local:input                                                               System.Collections
local:switch                                                              System.Collections
LogCommandHealthEvent                                                     System.Collections
LogCommandLifecycleEvent                                                  System.Collections
LogEngineHealthEvent                                                      System.Collections
LogEngineLifecycleEvent                                                   System.Collections
LogProviderHealthEvent                                                    System.Collections
LogProviderLifecycleEvent                                                 System.Collections
LogSettingsEvent                                                          System.Collections
Matches                                                                   System.Collections
MaximumHistoryCount                                                       System.Collections
MyInvocation                                                              System.Collections
NestedPromptLevel                                                         System.Collections
null                                                                      System.Collections
OFS                                                                       System.Collections
OutputEncoding                                                            System.Collections
PID                                                                       System.Collections
ProgressPreference                                                        System.Collections
PSBoundParameters                                                         System.Collections
PSCmdlet                                                                  System.Collections
PSCommandPath                                                             System.Collections
PSCulture                                                                 System.Collections
PSDebugContext                                                            System.Collections
PSDefaultParameterValues                                                  System.Collections
PSEmailServer                                                             System.Collections
PSHOME                                                                    System.Collections
PSItem                                                                    System.Collections
PSLogUserData                                                             System.Collections
PSModuleAutoLoadingPreference                                             System.Collections
PSScriptRoot                                                              System.Collections
PSSessionApplicationName                                                  System.Collections
PSSessionConfigurationName                                                System.Collections
PSUICulture                                                               System.Collections
PSVersionTable                                                            System.Collections
PWD                                                                       System.Collections
script:error                                                              System.Collections
ShellId                                                                   System.Collections
StackTrace                                                                System.Collections
switch                                                                    System.Collections
{System.Management.Automation.ActionPreference, System.Management.Auto... System.Collections
{System.Object, System.Object[], System.Object, System.Object...}         System.Collections
this                                                                      System.Collections
true                                                                      System.Collections
VerboseHelpErrors                                                         System.Collections
VerbosePreference                                                         System.Collections
WarningPreference                                                         System.Collections
WhatIfPreference                                                          System.Collections
$                                                                         System.Management.
?                                                                         System.Management.
{?, ConsoleFileName, ExecutionContext, false...}                          System.Management.
^                                                                         System.Management.
_                                                                         System.Management.
{_, args, this, input...}                                                 System.Management.
args                                                                      System.Management.
ConfirmPreference                                                         System.Management.
ConsoleFileName                                                           System.Management.
{ConsoleFileName, ExecutionContext, HOME, Host...}                        System.Management.
CurrentlyExecutingCommand                                                 System.Management.
DebugPreference                                                           System.Management.
{DebugPreference, VerbosePreference, ErrorActionPreference, WhatIfPref... System.Management.
env:PATHEXT                                                               System.Management.
error                                                                     System.Management.
ErrorActionPreference                                                     System.Management.
ErrorView                                                                 System.Management.
ExecutionContext                                                          System.Management.
false                                                                     System.Management.
foreach                                                                   System.Management.
global:$                                                                  System.Management.
global:^                                                                  System.Management.
global:error                                                              System.Management.
global:LASTEXITCODE                                                       System.Management.
global:NestedPromptLevel                                                  System.Management.
global:PSModuleAutoLoadingPreference                                      System.Management.
global:PSSessionApplicationName                                           System.Management.
global:PSSessionConfigurationName                                         System.Management.
global:PWD                                                                System.Management.
global:StackTrace                                                         System.Management.
HOME                                                                      System.Management.
Host                                                                      System.Management.
input                                                                     System.Management.
LASTEXITCODE                                                              System.Management.
local:args                                                                System.Management.
local:foreach                                                             System.Management.
local:input                                                               System.Management.
local:switch                                                              System.Management.
LogCommandHealthEvent                                                     System.Management.
LogCommandLifecycleEvent                                                  System.Management.
LogEngineHealthEvent                                                      System.Management.
LogEngineLifecycleEvent                                                   System.Management.
LogProviderHealthEvent                                                    System.Management.
LogProviderLifecycleEvent                                                 System.Management.
LogSettingsEvent                                                          System.Management.
Matches                                                                   System.Management.
MaximumHistoryCount                                                       System.Management.
MyInvocation                                                              System.Management.
NestedPromptLevel                                                         System.Management.
null                                                                      System.Management.
OFS                                                                       System.Management.
OutputEncoding                                                            System.Management.
PID                                                                       System.Management.
ProgressPreference                                                        System.Management.
PSBoundParameters                                                         System.Management.
PSCmdlet                                                                  System.Management.
PSCommandPath                                                             System.Management.
PSCulture                                                                 System.Management.
PSDebugContext                                                            System.Management.
PSDefaultParameterValues                                                  System.Management.
PSEmailServer                                                             System.Management.
PSHOME                                                                    System.Management.
PSItem                                                                    System.Management.
PSLogUserData                                                             System.Management.
PSModuleAutoLoadingPreference                                             System.Management.
PSScriptRoot                                                              System.Management.
PSSessionApplicationName                                                  System.Management.
PSSessionConfigurationName                                                System.Management.
PSUICulture                                                               System.Management.
PSVersionTable                                                            System.Management.
PWD                                                                       System.Management.
script:error                                                              System.Management.
ShellId                                                                   System.Management.
StackTrace                                                                System.Management.
switch                                                                    System.Management.
{System.Management.Automation.ActionPreference, System.Management.Auto... System.Management.
{System.Object, System.Object[], System.Object, System.Object...}         System.Management.
this                                                                      System.Management.
true                                                                      System.Management.
VerboseHelpErrors                                                         System.Management.
VerbosePreference                                                         System.Management.
WarningPreference                                                         System.Management.
WhatIfPreference                                                          System.Management.
$                                                                         System.String True
?                                                                         System.String True
{?, ConsoleFileName, ExecutionContext, false...}                          System.String True
^                                                                         System.String True
_                                                                         System.String True
{_, args, this, input...}                                                 System.String True
args                                                                      System.String True
ConfirmPreference                                                         System.String True
ConsoleFileName                                                           System.String True
{ConsoleFileName, ExecutionContext, HOME, Host...}                        System.String True
CurrentlyExecutingCommand                                                 System.String True
DebugPreference                                                           System.String True
{DebugPreference, VerbosePreference, ErrorActionPreference, WhatIfPref... System.String True
env:PATHEXT                                                               System.String True
error                                                                     System.String True
ErrorActionPreference                                                     System.String True
ErrorView                                                                 System.String True
ExecutionContext                                                          System.String True
false                                                                     System.String True
foreach                                                                   System.String True
global:$                                                                  System.String True
global:^                                                                  System.String True
global:error                                                              System.String True
global:LASTEXITCODE                                                       System.String True
global:NestedPromptLevel                                                  System.String True
global:PSModuleAutoLoadingPreference                                      System.String True
global:PSSessionApplicationName                                           System.String True
global:PSSessionConfigurationName                                         System.String True
global:PWD                                                                System.String True
global:StackTrace                                                         System.String True
HOME                                                                      System.String True
Host                                                                      System.String True
input                                                                     System.String True
LASTEXITCODE                                                              System.String True
local:args                                                                System.String True
local:foreach                                                             System.String True
local:input                                                               System.String True
local:switch                                                              System.String True
LogCommandHealthEvent                                                     System.String True
LogCommandLifecycleEvent                                                  System.String True
LogEngineHealthEvent                                                      System.String True
LogEngineLifecycleEvent                                                   System.String True
LogProviderHealthEvent                                                    System.String True
LogProviderLifecycleEvent                                                 System.String True
LogSettingsEvent                                                          System.String True
Matches                                                                   System.String True
MaximumHistoryCount                                                       System.String True
MyInvocation                                                              System.String True
NestedPromptLevel                                                         System.String True
null                                                                      System.String True
OFS                                                                       System.String True
OutputEncoding                                                            System.String True
PID                                                                       System.String True
ProgressPreference                                                        System.String True
PSBoundParameters                                                         System.String True
PSCmdlet                                                                  System.String True
PSCommandPath                                                             System.String True
PSCulture                                                                 System.String True
PSDebugContext                                                            System.String True
PSDefaultParameterValues                                                  System.String True
PSEmailServer                                                             System.String True
PSHOME                                                                    System.String True
PSItem                                                                    System.String True
PSLogUserData                                                             System.String True
PSModuleAutoLoadingPreference                                             System.String True
PSScriptRoot                                                              System.String True
PSSessionApplicationName                                                  System.String True
PSSessionConfigurationName                                                System.String True
PSUICulture                                                               System.String True
PSVersionTable                                                            System.String True
PWD                                                                       System.String True
script:error                                                              System.String True
ShellId                                                                   System.String True
StackTrace                                                                System.String True
switch                                                                    System.String True
{System.Management.Automation.ActionPreference, System.Management.Auto... System.String True
{System.Object, System.Object[], System.Object, System.Object...}         System.String True
this                                                                      System.String True
true                                                                      System.String True
VerboseHelpErrors                                                         System.String True
VerbosePreference                                                         System.String True
WarningPreference                                                         System.String True
WhatIfPreference                                                          System.String True
$                                                                         System.String[] Pr
?                                                                         System.String[] Pr
{?, ConsoleFileName, ExecutionContext, false...}                          System.String[] Pr
^                                                                         System.String[] Pr
_                                                                         System.String[] Pr
{_, args, this, input...}                                                 System.String[] Pr
args                                                                      System.String[] Pr
ConfirmPreference                                                         System.String[] Pr
ConsoleFileName                                                           System.String[] Pr
{ConsoleFileName, ExecutionContext, HOME, Host...}                        System.String[] Pr
CurrentlyExecutingCommand                                                 System.String[] Pr
DebugPreference                                                           System.String[] Pr
{DebugPreference, VerbosePreference, ErrorActionPreference, WhatIfPref... System.String[] Pr
env:PATHEXT                                                               System.String[] Pr
error                                                                     System.String[] Pr
ErrorActionPreference                                                     System.String[] Pr
ErrorView                                                                 System.String[] Pr
ExecutionContext                                                          System.String[] Pr
false                                                                     System.String[] Pr
foreach                                                                   System.String[] Pr
global:$                                                                  System.String[] Pr
global:^                                                                  System.String[] Pr
global:error                                                              System.String[] Pr
global:LASTEXITCODE                                                       System.String[] Pr
global:NestedPromptLevel                                                  System.String[] Pr
global:PSModuleAutoLoadingPreference                                      System.String[] Pr
global:PSSessionApplicationName                                           System.String[] Pr
global:PSSessionConfigurationName                                         System.String[] Pr
global:PWD                                                                System.String[] Pr
global:StackTrace                                                         System.String[] Pr
HOME                                                                      System.String[] Pr
Host                                                                      System.String[] Pr
input                                                                     System.String[] Pr
LASTEXITCODE                                                              System.String[] Pr
local:args                                                                System.String[] Pr
local:foreach                                                             System.String[] Pr
local:input                                                               System.String[] Pr
local:switch                                                              System.String[] Pr
LogCommandHealthEvent                                                     System.String[] Pr
LogCommandLifecycleEvent                                                  System.String[] Pr
LogEngineHealthEvent                                                      System.String[] Pr
LogEngineLifecycleEvent                                                   System.String[] Pr
LogProviderHealthEvent                                                    System.String[] Pr
LogProviderLifecycleEvent                                                 System.String[] Pr
LogSettingsEvent                                                          System.String[] Pr
Matches                                                                   System.String[] Pr
MaximumHistoryCount                                                       System.String[] Pr
MyInvocation                                                              System.String[] Pr
NestedPromptLevel                                                         System.String[] Pr
null                                                                      System.String[] Pr
OFS                                                                       System.String[] Pr
OutputEncoding                                                            System.String[] Pr
PID                                                                       System.String[] Pr
ProgressPreference                                                        System.String[] Pr
PSBoundParameters                                                         System.String[] Pr
PSCmdlet                                                                  System.String[] Pr
PSCommandPath                                                             System.String[] Pr
PSCulture                                                                 System.String[] Pr
PSDebugContext                                                            System.String[] Pr
PSDefaultParameterValues                                                  System.String[] Pr
PSEmailServer                                                             System.String[] Pr
PSHOME                                                                    System.String[] Pr
PSItem                                                                    System.String[] Pr
PSLogUserData                                                             System.String[] Pr
PSModuleAutoLoadingPreference                                             System.String[] Pr
PSScriptRoot                                                              System.String[] Pr
PSSessionApplicationName                                                  System.String[] Pr
PSSessionConfigurationName                                                System.String[] Pr
PSUICulture                                                               System.String[] Pr
PSVersionTable                                                            System.String[] Pr
PWD                                                                       System.String[] Pr
script:error                                                              System.String[] Pr
ShellId                                                                   System.String[] Pr
StackTrace                                                                System.String[] Pr
switch                                                                    System.String[] Pr
{System.Management.Automation.ActionPreference, System.Management.Auto... System.String[] Pr
{System.Object, System.Object[], System.Object, System.Object...}         System.String[] Pr
this                                                                      System.String[] Pr
true                                                                      System.String[] Pr
VerboseHelpErrors                                                         System.String[] Pr
VerbosePreference                                                         System.String[] Pr
WarningPreference                                                         System.String[] Pr
WhatIfPreference                                                          System.String[] Pr
$                                                                         System.Type[] Pref
?                                                                         System.Type[] Pref
{?, ConsoleFileName, ExecutionContext, false...}                          System.Type[] Pref
^                                                                         System.Type[] Pref
_                                                                         System.Type[] Pref
{_, args, this, input...}                                                 System.Type[] Pref
args                                                                      System.Type[] Pref
ConfirmPreference                                                         System.Type[] Pref
ConsoleFileName                                                           System.Type[] Pref
{ConsoleFileName, ExecutionContext, HOME, Host...}                        System.Type[] Pref
CurrentlyExecutingCommand                                                 System.Type[] Pref
DebugPreference                                                           System.Type[] Pref
{DebugPreference, VerbosePreference, ErrorActionPreference, WhatIfPref... System.Type[] Pref
env:PATHEXT                                                               System.Type[] Pref
error                                                                     System.Type[] Pref
ErrorActionPreference                                                     System.Type[] Pref
ErrorView                                                                 System.Type[] Pref
ExecutionContext                                                          System.Type[] Pref
false                                                                     System.Type[] Pref
foreach                                                                   System.Type[] Pref
global:$                                                                  System.Type[] Pref
global:^                                                                  System.Type[] Pref
global:error                                                              System.Type[] Pref
global:LASTEXITCODE                                                       System.Type[] Pref
global:NestedPromptLevel                                                  System.Type[] Pref
global:PSModuleAutoLoadingPreference                                      System.Type[] Pref
global:PSSessionApplicationName                                           System.Type[] Pref
global:PSSessionConfigurationName                                         System.Type[] Pref
global:PWD                                                                System.Type[] Pref
global:StackTrace                                                         System.Type[] Pref
HOME                                                                      System.Type[] Pref
Host                                                                      System.Type[] Pref
input                                                                     System.Type[] Pref
LASTEXITCODE                                                              System.Type[] Pref
local:args                                                                System.Type[] Pref
local:foreach                                                             System.Type[] Pref
local:input                                                               System.Type[] Pref
local:switch                                                              System.Type[] Pref
LogCommandHealthEvent                                                     System.Type[] Pref
LogCommandLifecycleEvent                                                  System.Type[] Pref
LogEngineHealthEvent                                                      System.Type[] Pref
LogEngineLifecycleEvent                                                   System.Type[] Pref
LogProviderHealthEvent                                                    System.Type[] Pref
LogProviderLifecycleEvent                                                 System.Type[] Pref
LogSettingsEvent                                                          System.Type[] Pref
Matches                                                                   System.Type[] Pref
MaximumHistoryCount                                                       System.Type[] Pref
MyInvocation                                                              System.Type[] Pref
NestedPromptLevel                                                         System.Type[] Pref
null                                                                      System.Type[] Pref
OFS                                                                       System.Type[] Pref
OutputEncoding                                                            System.Type[] Pref
PID                                                                       System.Type[] Pref
ProgressPreference                                                        System.Type[] Pref
PSBoundParameters                                                         System.Type[] Pref
PSCmdlet                                                                  System.Type[] Pref
PSCommandPath                                                             System.Type[] Pref
PSCulture                                                                 System.Type[] Pref
PSDebugContext                                                            System.Type[] Pref
PSDefaultParameterValues                                                  System.Type[] Pref
PSEmailServer                                                             System.Type[] Pref
PSHOME                                                                    System.Type[] Pref
PSItem                                                                    System.Type[] Pref
PSLogUserData                                                             System.Type[] Pref
PSModuleAutoLoadingPreference                                             System.Type[] Pref
PSScriptRoot                                                              System.Type[] Pref
PSSessionApplicationName                                                  System.Type[] Pref
PSSessionConfigurationName                                                System.Type[] Pref
PSUICulture                                                               System.Type[] Pref
PSVersionTable                                                            System.Type[] Pref
PWD                                                                       System.Type[] Pref
script:error                                                              System.Type[] Pref
ShellId                                                                   System.Type[] Pref
StackTrace                                                                System.Type[] Pref
switch                                                                    System.Type[] Pref
{System.Management.Automation.ActionPreference, System.Management.Auto... System.Type[] Pref
{System.Object, System.Object[], System.Object, System.Object...}         System.Type[] Pref
this                                                                      System.Type[] Pref
true                                                                      System.Type[] Pref
VerboseHelpErrors                                                         System.Type[] Pref
VerbosePreference                                                         System.Type[] Pref
WarningPreference                                                         System.Type[] Pref
WhatIfPreference                                                          System.Type[] Pref

[string]型がビルトイン変数

ということで、[System.String]に該当するuserpathがビルトイン変数のようです。 それなら話は簡単で、コレで
[psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') `
    | Where-Object {$_.FieldType -eq ([string])} `
    | ForEach-Object {$_.GetValue($null)}
PowerShell 3.0では、{}を省略可能になったので…
[psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') `
    | Where-Object FieldType -eq ([string]) `
    | ForEach-Object GetValue $null
MaximumHistoryCount
MyInvocation
OFS
OutputEncoding
VerboseHelpErrors
LogEngineHealthEvent
LogEngineLifecycleEvent
LogCommandHealthEvent
LogCommandLifecycleEvent
LogProviderHealthEvent
LogProviderLifecycleEvent
LogSettingsEvent
PSLogUserData
NestedPromptLevel
CurrentlyExecutingCommand
PSBoundParameters
Matches
LASTEXITCODE
PSDebugContext
StackTrace
^
$
PSItem
_
?
args
this
input
PSCmdlet
error
error
env:PATHEXT
PSEmailServer
PSDefaultParameterValues
PSScriptRoot
PSCommandPath
foreach
switch
PWD
null
true
false
PSModuleAutoLoadingPreference
DebugPreference
ErrorActionPreference
ProgressPreference
VerbosePreference
WarningPreference
WhatIfPreference
ConfirmPreference
ErrorView
PSSessionConfigurationName
PSSessionApplicationName
ConsoleFileName
ExecutionContext
HOME
Host
PID
PSCulture
PSHOME
PSUICulture
PSVersionTable
ShellId

ユーザー定義変数だけ抽出したい

ここまでくれば、ユーザー定義変数だけを出すこともできますね。 まず、このままではビルトイン変数に足りないものがありますので洗い出します。 PowerShellを一度閉じてユーザー定義変数をクリアにした状態で実行します。
$builtinVariable = [psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') | Where-Object FieldType -eq ([string]) | ForEach-Object GetValue $null
$other = Get-Variable | ?{$_.Name -notin $builtinVariable}
$other.Name
一覧です。
builtinVariable
FormatEnumerationLimit
MaximumAliasCount
MaximumDriveCount
MaximumErrorCount
MaximumFunctionCount
MaximumVariableCount
profile
psISE
PSSessionOption
一番上のbuildinVariableを除く、これらを足してあげましょう。
$other | where {$_.Name -ne "builtinVariable"} | ForEach-Object {$builtinVariable += $_.Name.ToString()}
[05/March/2013改定] 上記は、起動直後しか有効になりません。 実際は、以下のハードコード対応が必要です。
    $other = , @(
		"FormatEnumerationLimit",
		"MaximumAliasCount",
		"MaximumDriveCount",
		"MaximumErrorCount",
		"MaximumFunctionCount",
		"MaximumVariableCount",
		"PGHome",
		"PGSE",
		"PGUICulture",
		"PGVersionTable",
		"PROFILE",
		"PSSessionOption"
		)

    $other `
        | ForEach-Object {$builtinVariable += $_}
で出力と。
$builtinVariable
キッチリ増えてますね。
MaximumHistoryCount
MyInvocation
OFS
OutputEncoding
VerboseHelpErrors
LogEngineHealthEvent
LogEngineLifecycleEvent
LogCommandHealthEvent
LogCommandLifecycleEvent
LogProviderHealthEvent
LogProviderLifecycleEvent
LogSettingsEvent
PSLogUserData
NestedPromptLevel
CurrentlyExecutingCommand
PSBoundParameters
Matches
LASTEXITCODE
PSDebugContext
StackTrace
^
$
PSItem
_
?
args
this
input
PSCmdlet
error
error
env:PATHEXT
PSEmailServer
PSDefaultParameterValues
PSScriptRoot
PSCommandPath
foreach
switch
PWD
null
true
false
PSModuleAutoLoadingPreference
DebugPreference
ErrorActionPreference
ProgressPreference
VerbosePreference
WarningPreference
WhatIfPreference
ConfirmPreference
ErrorView
PSSessionConfigurationName
PSSessionApplicationName
ConsoleFileName
ExecutionContext
HOME
Host
PID
PSCulture
PSHOME
PSUICulture
PSVersionTable
ShellId
FormatEnumerationLimit
MaximumAliasCount
MaximumDriveCount
MaximumErrorCount
MaximumFunctionCount
MaximumVariableCount
profile
psISE
PSSessionOption
psUnsupportedConsoleApplications
ここまでくれば、ユーザー定義変数との照合も簡単です。 Get-Variableのすべての変数出力と、$builtInVariableを照合するだけです。
Get-Variable `
    | Where {$_.Name -notin $builtinVariable} `
    | select Name, Value, Description

ユーザー定義変数取得Function

[05/March/2013改定] ではFunction化してみます。
function Get-UserVariables{

    param(
    )

    $builtinVariable = [psobject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') `
        | Where-Object FieldType -eq ([string]) `
        | ForEach-Object GetValue $null

    $other = , @(
		"FormatEnumerationLimit",
		"MaximumAliasCount",
		"MaximumDriveCount",
		"MaximumErrorCount",
		"MaximumFunctionCount",
		"MaximumVariableCount",
		"PGHome",
		"PGSE",
		"PGUICulture",
		"PGVersionTable",
		"PROFILE",
		"PSSessionOption"
		)

    $other `
        | ForEach-Object {$builtinVariable += $_}

    Get-Variable `
        | Where {$_.Name -notin $builtinVariable} `
        | select Name, Value, Description

}
実行は、一文だけです。
Get-UserVariables | Format-List
Functionで利用した変数だけですね!
Name        : builtinVariable
Value       : {MaximumHistoryCount, MyInvocation, OFS, OutputEncoding...}
Description :

Name        : other
Value       : {FormatEnumerationLimit MaximumAliasCount MaximumDriveCount MaximumErrorCount MaximumFunctionCount MaximumVariableCount PGHome PGSE PGUICulture PGV
              ersionTable PROFILE PSSessionOption}
Description :

まとめ

PowerGUIをつかいましょう。