Posts Tagged ‘scoping’


PowerShell Scoping – Revisited

Wednesday, April 10th, 2013 by David Corrales
Yes, we said we would not speak of it again, but a user post provided a good example of the change in scoping rules between PowerShell V2 and V3. This particular user had a question about GUI controls on our new PowerShell GUIs forum and provided an example GUI script. In the example, the user declared a function inside an event script block: $OnLoadFormEvent={ #TODO: Initialize Form Controls here $t = dir c:\PowerShell\ $t2 = dir c:\Scoping\ function outTextBox1($textOut) { $richtextbox1.Text = $richtextbox1.Text + $textOut } } This script block is called when the GUI Window is about to display.…   More »

First rule of PowerShell scoping rules…

Wednesday, March 6th, 2013 by Alex Riedel
… never talk about PowerShell scoping rules. Judging from the posts, emails and questions we get about variable scope in PowerShell Studio forms, PowerShell scoping rules are shrouded in mystery. When you read about_scopes you get a lot of information. When you come from any other scripting language, for example VBScript, you are used to two scopes; global and local. The default scope of a variable in VBScript depends on its first use or its declaration. So if you want a variable to have a specific scope you just declare it with a DIM statement. This code sample illustrates…   More »