Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Passing Variables Between Scripts - Is it possible?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59657
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Passing Variables Between Scripts - Is it possible?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Passing Variables Between Scripts - Is it possible? - 4/30/2008 4:00:33 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Hi...i'd like to figure out how to pass variables created in one script into another. In this situation, VBScript --> PowerShell. Is this possible to do? I'd rather not have to prompt the user a 2nd time for the information.
 
 
Post #: 1
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 4:09:09 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well, it sort of depends on how you implement the Powershell script. Powershell supports command line parameters for the script so the easiest way is to just run the PS script and pass the values in at the command line.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 2
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 7:06:47 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
How would i do that. i assume that when i invoke the PowerShell script using the VBScript, i would just place the variables within the objShell.Run part, but i wouldnt know the proper syntax.

(in reply to GreatBarrier86)
 
 
Post #: 3
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 7:12:06 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well the first thing to do is to write the PS to take command line parameters. In the process of testing that you will determine exactly what the command line to run the script needs to be structured like.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 4
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 7:23:45 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Well, i have some research to do. i have no idea how to write the PS to take parameters.

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 7:26:54 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Make a .ps1 file with just this line in it:

$args

Let's say that you called it C:\Temp\Test.ps1

From a regular DOS prompt run this:

powershell -command "C:\Temp\test.ps1 foo bar"

The foo and bar are command line parameters to the PS script.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 6
 
 RE: Passing Variables Between Scripts - Is it possible? - 4/30/2008 7:37:32 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
But how do i get them into seperate variables. I want to pass a username and password to the PoSh script

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Passing Variables Between Scripts - Is it possible? - 5/1/2008 12:25:52 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Call the script like this:

powershell -command "C:\Temp\test.ps1 USER PASS"

Then in the script do this:


$user = $args[0];
$pass = $args[1];

Write-Host "The user is $user and the password is $pass";

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 8
 
 RE: Passing Variables Between Scripts - Is it possible? - 5/16/2008 3:20:25 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Sorry EB. i just noticed you sent this. I wanted to say thanks.

(in reply to ebgreen)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Passing Variables Between Scripts - Is it possible? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts