header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Subject: Scope problem...
Prev Next
You are not authorized to post a reply.

Author Messages
darthchocoboUser is Offline
New Member
New Member
Posts:2

07/21/2008 10:01 AM  

Ok so i have this very simple script. Now When i execute this script it should be all "Hello" becuase of the dot sourcing right? But when i execute it it goes Hello Hello Good Bye Good Bye as if it is making the scope of the script the scope of the function not the other way around. Thank you for your time and help,

 

 

 

 

$var1 = "Hello"
   
        Function TheFunction{
            Write-Host $var1
            $var1 = "GoodBye"
            Write-Host $var1
            }
            Write-Host $var1
            . TheFunction
            Write-Host $var1
   

EdengundamUser is Offline
New Member
New Member
Posts:3

08/12/2008 8:09 AM  
hi,
the following code:
Function TheFunction{
Write-Host $var1
$var1 = "GoodBye"
Write-Host $var1
}
is the definition. In the other words, it is a piece of code without executed.
When you dot "TheFunction", it will change the value of $var1.
glnsizeUser is Offline
Shell Enthusiast
Shell Enthusiast
Posts:60

08/12/2008 6:21 PM  

errr... It's getting wiered again. This was posted a couple weeks ago...

http://powershellcommunity.org/Forums/tabid/54/forumid/1/tpage/1/view/topic/postid/2286/Default.aspx#2299

halr9000User is Offline
CLI Addict
CLI Addict
Posts:245


08/12/2008 6:30 PM  
I suspect Alzhimer's.

Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)
Author, TechProsaic (http://halr9000.com)
You are not authorized to post a reply.



ActiveForums 3.7
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer