Last active
March 26, 2016 18:08
-
-
Save ferventcoder/132560fc67fe92d1fb2a to your computer and use it in GitHub Desktop.
Automatic Variables In PowerShell - Attempting to detect differences between PowerShell and System.Management.Automation Custom PowerShell Host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Log-VariableValue { | |
| param ( | |
| [string] $Name | |
| ) | |
| $varValue = $ExecutionContext.InvokeCommand.ExpandString("$" + $Name) | |
| Write-Host "`$$Name = '$varValue'" | |
| } | |
| # http://ss64.com/ps/syntax-automatic-variables.html | |
| # https://www.safaribooksonline.com/library/view/windows-powershell-pocket/9780596521783/ch04.html | |
| Write-Warning "_Automatic Variables_" | |
| Log-VariableValue "$" | |
| Log-VariableValue "?" | |
| Log-VariableValue "^" | |
| Log-VariableValue "_" | |
| Log-VariableValue "args" | |
| Log-VariableValue "ConfirmPreference" | |
| Log-VariableValue "ConsoleFileName" | |
| Log-VariableValue "CurrentlyExecutingCommand" | |
| Log-VariableValue "DebugPreference" | |
| Log-VariableValue "Error" | |
| Log-VariableValue "ErrorActionPreference" | |
| Log-VariableValue "ErrorView" | |
| Log-VariableValue "Event" | |
| Log-VariableValue "EventSubscriber" | |
| Log-VariableValue "ExecutionContext" | |
| Log-VariableValue "False" | |
| Log-VariableValue "ForEach" | |
| Log-VariableValue "FormatEnumerationLimit" | |
| Log-VariableValue "Home" | |
| Log-VariableValue "Host" | |
| Log-VariableValue "Input" | |
| Log-VariableValue "LastExitCode" | |
| Log-VariableValue "LogEngineHealthEvent" | |
| Log-VariableValue "LogCommandHealthEvent" | |
| Log-VariableValue "LogCommandLifecycleEvent" | |
| Log-VariableValue "LogProviderHealthEvent" | |
| Log-VariableValue "LogProviderLifecycleEvent" | |
| Log-VariableValue "Matches" | |
| Log-VariableValue "MaximumAliasCount" | |
| Log-VariableValue "MaximumDriveCount" | |
| Log-VariableValue "MaximumErrorCount" | |
| Log-VariableValue "MaximumFunctionCount" | |
| Log-VariableValue "MaximumHistoryCount" | |
| Log-VariableValue "MaximumVariableCount" | |
| Log-VariableValue "MyInvocation" | |
| Log-VariableValue "NestedPromptLevel" | |
| Log-VariableValue "NULL" | |
| Log-VariableValue "OFS" #Output field separator. | |
| Log-VariableValue "OutputEncoding" | |
| Log-VariableValue "PID" | |
| Log-VariableValue "Profile" | |
| Log-VariableValue "ProgressPreference" | |
| Log-VariableValue "PSBoundParameters" | |
| Log-VariableValue "PsCmdlet" | |
| Log-VariableValue "PsCulture" | |
| Log-VariableValue "PsDebugContext" | |
| Log-VariableValue "PsHome" | |
| Log-VariableValue "PsItem" | |
| Log-VariableValue "PsScriptRoot" | |
| Log-VariableValue "PsUICulture" | |
| Log-VariableValue "PsVersionTable" | |
| Log-VariableValue "Pwd" | |
| Log-VariableValue "Sender" | |
| Log-VariableValue "ShellID" | |
| Log-VariableValue "SourceArgs" | |
| Log-VariableValue "SourceEventArgs" | |
| Log-VariableValue "StackTrace" | |
| Log-VariableValue "This" | |
| Log-VariableValue "Transcript" | |
| Log-VariableValue "True" | |
| Log-VariableValue "VerboseHelpErrors" | |
| Log-VariableValue "VerbosePreference" | |
| Log-VariableValue "WarningPreference" | |
| Log-VariableValue "WhatIfPreference" | |
| $host | Format-List * -Force | %{ Write-Output $_ } | |
| $PSVersionTable | Format-List * -Force | %{ Write-Output $_ } | |
| $MyInvocation | Format-List * -Force | %{ Write-Output $_ } | |
| $PSBoundParameters | Format-List * -Force | %{ Write-Output $_ } | |
| Write-Output "" | |
| Write-Output "_Profiles_" | |
| Write-Output "CurrentUserCurrentHost = '$($Profile.CurrentUserCurrentHost)'" | |
| Write-Output "CurrentUserAllHosts = '$($Profile.CurrentUserAllHosts)'" | |
| Write-Output "AllUsersCurrentHost = '$($Profile.AllUsersCurrentHost)'" | |
| Write-Output "AllUsersAllHosts = '$($Profile.AllUsersAllHosts)'" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $$ = '' | |
| $? = 'True' | |
| $^ = '' | |
| $_ = '' | |
| $args = '' | |
| $ConfirmPreference = 'High' | |
| $ConsoleFileName = '' | |
| $CurrentlyExecutingCommand = '' | |
| $DebugPreference = 'Continue' | |
| $Error = '' | |
| $ErrorActionPreference = 'Continue' | |
| $ErrorView = 'NormalView' | |
| $Event = '' | |
| $EventSubscriber = '' | |
| $ExecutionContext = 'System.Management.Automation.EngineIntrinsics' | |
| $False = 'False' | |
| $ForEach = '' | |
| $FormatEnumerationLimit = '4' | |
| $Home = 'C:\Users\rob' | |
| $Host = 'System.Management.Automation.Internal.Host.InternalHost' | |
| $Input = '' | |
| $LastExitCode = '' | |
| $LogEngineHealthEvent = '' | |
| $LogCommandHealthEvent = '' | |
| $LogCommandLifecycleEvent = '' | |
| $LogProviderHealthEvent = '' | |
| $LogProviderLifecycleEvent = '' | |
| $Matches = '' | |
| $MaximumAliasCount = '4096' | |
| $MaximumDriveCount = '4096' | |
| $MaximumErrorCount = '256' | |
| $MaximumFunctionCount = '4096' | |
| $MaximumHistoryCount = '4096' | |
| $MaximumVariableCount = '4096' | |
| $MyInvocation = 'System.Management.Automation.InvocationInfo' | |
| $NestedPromptLevel = '0' | |
| $NULL = '' | |
| $OFS = '' | |
| $OutputEncoding = 'System.Text.ASCIIEncoding' | |
| $PID = '1508' | |
| $Profile = '' | |
| $ProgressPreference = 'Continue' | |
| $PSBoundParameters = 'System.Management.Automation.PSBoundParametersDictionary' | |
| $PsCmdlet = '' | |
| $PsCulture = 'en-US' | |
| $PsDebugContext = '' | |
| $PsHome = 'C:\Windows\System32\WindowsPowerShell\v1.0' | |
| $PsItem = '' | |
| $PsScriptRoot = 'C:\ProgramData\chocolatey\lib\testprofile\tools' | |
| $PsUICulture = 'en-US' | |
| $PsVersionTable = 'System.Management.Automation.PSVersionHashTable' | |
| $Pwd = 'C:\temp\temp_packages\testProfile' | |
| $Sender = '' | |
| $ShellID = 'Microsoft.PowerShell' | |
| $SourceArgs = '' | |
| $SourceEventArgs = '' | |
| $StackTrace = '' | |
| $This = '' | |
| $Transcript = '' | |
| $True = 'True' | |
| $VerboseHelpErrors = '' | |
| $VerbosePreference = 'Continue' | |
| $WarningPreference = 'Continue' | |
| $WhatIfPreference = 'False' | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupEndData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEndData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupEndData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEndData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupStartData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData | |
| Microsoft.PowerShell.Commands.Internal.Format.GroupEndData | |
| Microsoft.PowerShell.Commands.Internal.Format.FormatEndData | |
| _Profiles_ | |
| CurrentUserCurrentHost = '' | |
| CurrentUserAllHosts = '' | |
| AllUsersCurrentHost = '' | |
| AllUsersAllHosts = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $$ = '' | |
| $? = 'True' | |
| $^ = '' | |
| $_ = '' | |
| $args = '' | |
| $ConfirmPreference = 'High' | |
| $ConsoleFileName = '' | |
| $CurrentlyExecutingCommand = '' | |
| $DebugPreference = 'SilentlyContinue' | |
| $Error = '' | |
| $ErrorActionPreference = 'Continue' | |
| $ErrorView = 'NormalView' | |
| $Event = '' | |
| $EventSubscriber = '' | |
| $ExecutionContext = 'System.Management.Automation.EngineIntrinsics' | |
| $False = 'False' | |
| $ForEach = '' | |
| $FormatEnumerationLimit = '4' | |
| $Home = 'C:\Users\rob' | |
| $Host = 'System.Management.Automation.Internal.Host.InternalHost' | |
| $Input = '' | |
| $LastExitCode = '0' | |
| $LogEngineHealthEvent = '' | |
| $LogCommandHealthEvent = '' | |
| $LogCommandLifecycleEvent = '' | |
| $LogProviderHealthEvent = '' | |
| $LogProviderLifecycleEvent = '' | |
| $Matches = '' | |
| $MaximumAliasCount = '4096' | |
| $MaximumDriveCount = '4096' | |
| $MaximumErrorCount = '256' | |
| $MaximumFunctionCount = '4096' | |
| $MaximumHistoryCount = '4096' | |
| $MaximumVariableCount = '4096' | |
| $MyInvocation = 'System.Management.Automation.InvocationInfo' | |
| $NestedPromptLevel = '0' | |
| $NULL = '' | |
| $OFS = '' | |
| $OutputEncoding = 'System.Text.ASCIIEncoding' | |
| $PID = '2912' | |
| $Profile = 'C:\Users\rob\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' | |
| $ProgressPreference = 'Continue' | |
| $PSBoundParameters = 'System.Management.Automation.PSBoundParametersDictionary' | |
| $PsCmdlet = '' | |
| $PsCulture = 'en-US' | |
| $PsDebugContext = '' | |
| $PsHome = 'C:\Windows\System32\WindowsPowerShell\v1.0' | |
| $PsItem = '' | |
| $PsScriptRoot = 'C:\temp\temp_packages\testProfile\tools' | |
| $PsUICulture = 'en-US' | |
| $PsVersionTable = 'System.Management.Automation.PSVersionHashTable' | |
| $Pwd = 'C:\Users\rob' | |
| $Sender = '' | |
| $ShellID = 'Microsoft.PowerShell' | |
| $SourceArgs = '' | |
| $SourceEventArgs = '' | |
| $StackTrace = '' | |
| $This = '' | |
| $Transcript = '' | |
| $True = 'True' | |
| $VerboseHelpErrors = '' | |
| $VerbosePreference = 'SilentlyContinue' | |
| $WarningPreference = 'Continue' | |
| $WhatIfPreference = 'False' | |
| Name : ConsoleHost | |
| Version : 3.0 | |
| InstanceId : 8e335671-fcee-446f-9e43-7dd18b8fa6e0 | |
| UI : System.Management.Automation.Internal.Host.InternalHostUserI | |
| nterface | |
| CurrentCulture : en-US | |
| CurrentUICulture : en-US | |
| PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy | |
| IsRunspacePushed : False | |
| Runspace : System.Management.Automation.Runspaces.LocalRunspace | |
| Key : PSVersion | |
| Value : 3.0 | |
| Name : PSVersion | |
| Key : WSManStackVersion | |
| Value : 3.0 | |
| Name : WSManStackVersion | |
| Key : SerializationVersion | |
| Value : 1.1.0.1 | |
| Name : SerializationVersion | |
| Key : CLRVersion | |
| Value : 4.0.30319.34209 | |
| Name : CLRVersion | |
| Key : BuildVersion | |
| Value : 6.2.9200.16398 | |
| Name : BuildVersion | |
| Key : PSCompatibleVersions | |
| Value : {1.0, 2.0, 3.0} | |
| Name : PSCompatibleVersions | |
| Key : PSRemotingProtocolVersion | |
| Value : 2.2 | |
| Name : PSRemotingProtocolVersion | |
| MyCommand : chocolateyinstall.ps1 | |
| BoundParameters : {} | |
| UnboundArguments : {} | |
| ScriptLineNumber : 1 | |
| OffsetInLine : 1 | |
| HistoryId : 10 | |
| ScriptName : | |
| Line : & C:\temp\temp_packages\testProfile\tools\chocolateyins | |
| tall.ps1 | |
| PositionMessage : At line:1 char:1 | |
| + & C:\temp\temp_packages\testProfile\tools\chocolateyi | |
| nstall.ps1 | |
| + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| ~~~~~~~~~~ | |
| PSScriptRoot : | |
| PSCommandPath : | |
| InvocationName : & | |
| PipelineLength : 1 | |
| PipelinePosition : 1 | |
| ExpectingInput : False | |
| CommandOrigin : Runspace | |
| DisplayScriptPosition : | |
| _Profiles_ | |
| CurrentUserCurrentHost = 'C:\Users\rob\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' | |
| CurrentUserAllHosts = 'C:\Users\rob\Documents\WindowsPowerShell\profile.ps1' | |
| AllUsersCurrentHost = 'C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1' | |
| AllUsersAllHosts = 'C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$psscriptroot is different due to where the two packages were executed.