![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Novice question: How I can query for a variable scope? This is related to: RE: Issues of executing a script block in a function 1. How I can query for a variable scope? I.e. I have a variable $a. How can I tell which scope it belongs to? Knowing it will greatly to help with debugging! :-) 1.1. Which scope a function parameter belongs to? 1.2.1. Which scope a script (i.e. file with extension ps1) named parameters/arguments belongs to? 1.2.2. Which scope a script block (i.e. {…}) parameter/argument belongs to? --------------------------------------------------- From "PowerShell User Guide.doc": The PowerShell provides four labels for identifying the scope of a variable: local global private script ---------------------------------------------------- ## -- cut here ------------------------------------------------ function test { "-- function test -----------------------" "-- local: {0}" -f $local:a "-- global: {0}" -f $global:a "-- private: {0}" -f $private:a "-- script: {0}" -f $script:a } [string] $local:a = "I'm local" [string] $global:a = "I'm global" [string] $private:a = "I'm local" [string] $script:a = "I'm script" "-- local: {0}" -f $local:a "-- global: {0}" -f $global:a "-- private: {0}" -f $private:a "-- script: {0}" -f $script:a test ## -- cut here ------------------------------------------------ ****** output ************************************************* -- local: I'm script -- global: I'm global -- private: I'm script -- script: I'm script -- function test ----------------------- -- local: -- global: I'm global -- private: -- script: I'm script |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Scope of Err Variable | VB Script | |||
| Problem with variable scope | PowerShell | |||
| Variable scope | PowerShell | |||
| Potenial issue with the get-variable -scope parameter | PowerShell | |||
| variable inside of a SQL query | PowerShell | |||