header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Variable scope, global vars?
Last Post 06 Sep 2010 03:01 PM by Marco Shaw (MVP). 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
rmse17User is Offline
New Member
New Member
Posts:2
Avatar

--
06 Sep 2010 09:49 AM
    I have a script A which calls a script B.
    Script A has a variable $var.  Script B assigns a value to variable $var.

    When script B finishes, and I get the value of $var in script A, the value remains unchanged (original value, not what B set it as.)

    It's as if B changes a copy of $var, not the original $var that was in A.  I need changes that script B makes to $var to stay.

    I tried defining $var as global in A, Set-Variable var -scope global.

    But the same thing happens. 

    Thanks for your help!
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1641
    Avatar

    --
    06 Sep 2010 03:01 PM
    Can you show us your scripts? Make sure you the proper syntax both when reading and stiing the variable. A shortcut is to simply use the syntax $global:var.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer