April 26th, 2014

PowerTip: Use PowerShell to Look Up Variable Values

Doctor Scripto
Scripter

Summary: Look up variable values in the caller’s scope.

Hey, Scripting Guy! Question I’m writing a Windows PowerShell advanced function in a script module. How can I look up the value of
          variables set in my caller’s scope?

Hey, Scripting Guy! Answer Use the $PSCmdlet.GetVariableValue() method:

[CmdletBinding()]

param ( )

$variableValue = $PSCmdlet.GetVariableValue(‘variableName’)

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback