Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

returning values to original script

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-25-2007   #1 (permalink)
Frank
Guest


 

returning values to original script

Hi,

I have a script called menu.ps1 which calls another PS script,
getvalues.ps1. In getvalues.ps1, I do some console interaction with the
user. Depending on the interaction, I need to return a value back to the
original menu.ps1 script. I tried to do a return "$value" but that didn't
work. What did work was to define a global variable via: $global:testvar.
Is that the best way to return a value back to the original script? I rather
not use a global variable if I didn't to.

Thanks,



My System SpecsSystem Spec
Old 05-25-2007   #2 (permalink)
Keith Hill [MVP]
Guest


 

Re: returning values to original script

"Frank" <Frank@discussions.microsoft.com> wrote in message news:4BA19C3B-93B1-4974-8198-4CB22128CB34@microsoft.com...
> Hi,
>
> I have a script called menu.ps1 which calls another PS script,
> getvalues.ps1. In getvalues.ps1, I do some console interaction with the
> user. Depending on the interaction, I need to return a value back to the
> original menu.ps1 script. I tried to do a return "$value" but that didn't
> work. What did work was to define a global variable via: $global:testvar.
> Is that the best way to return a value back to the original script? I rather
> not use a global variable if I didn't to.
>


Basically anything output by a script that is not redirected to a file or captured by a variable is consider the output of a script. Try this:

24> 'gps | ?{$_.PM -gt 50MB}' > memhogs.ps1
25> $hogs = .\memhogs.ps1
26> $hogs

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
472 15 68496 31820 278 40.30 4336 dexplore
210 9 123580 67140 226 1,411.63 1356 dwm
1847 51 173084 100272 433 1,957.20 4020 iexplore
711 32 95136 38468 310 ...21.83 4720 iexplore
458 11 83912 52356 239 143.56 4128 powershell
738 21 60228 45632 189 1,883.27 3624 sidebar
636 20 66636 63912 163 1168 svchost\

In fact the trickier problem is getting rid of unwanted script output i.e. some innocous like this:

"Starting script memhogs.ps1"

is added to the output of your script. To avoid that you would do this:

write-host "Starting script memhogs.ps1"

--
Keith
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Include another script, keep variables in included script? pschmidt PowerShell 32 08-18-2008 01:48 PM
How to get in a vbs script the sum of values of a Excel cells in a certain range? Claudia d'Amato VB Script 1 06-26-2008 12:58 PM
quoting original text doesn't work if original mail is UTF-8 discohr Vista mail 8 09-20-2007 07:08 PM
Script file has 'OS Handle' error when run from script Jay PowerShell 1 09-18-2007 07:06 PM
Returning from RC2 to RC1 Kevin Young Vista General 4 10-09-2006 03:09 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008