# encoding: ascii
# api: powershell
# title: Get-Field
# description: Displays private fields of passed object. This function is useful only if you want to want to see what is under the hood in powershell
# version: 0.1
# type: function
# author: Andrew Savinykh
# license: CC0
# function: Get-Field
# x-poshcode-id: 2057
# x-archived: 2016-01-25T19:22:25
# x-published: 2011-08-10T05:04:00
#
#
function Get-Field{
[CmdletBinding()]
param (
[Parameter(Position=0,Mandatory=$true)]
$InputObject
)
$type = $InputObject.gettype()
$publicNonPublic = [Reflection.BindingFlags]::Public -bor [Reflection.BindingFlags]::NonPublic
$instance = $publicNonPublic -bor [Reflection.BindingFlags]::Instance
$getField = $instance -bor [Reflection.BindingFlags]::GetField
$fields = $type.GetFields($instance)
$result = @{}
$fields | Foreach-Object { $result[$_.Name] = $type.InvokeMember($_.Name, $getField, $null, $InputObject, $null) }
$result
}
##Example:
##$context = (Get-Field $ExecutionContext)._context
##$context
##Get-Field $context
##$sessionState = (Get-Field $context)._enginesessionstate
##$sessionState
##$moduleTable = (Get-Field $sessionState)._moduleTable
##$moduleTable