![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) | ||||||||||||
| Guest | How does return work in powershell functions Hey script quys. I am trying to understand the return values for functions in Powershell I defined a simple function in a script file. function foo( [string] $ss ) { $sb = new "System.Text.StringBuilder" $sb.Append( $ss ) return $sb } I dot sourced it and then
Capacity MaxCapacity Length -------- ----------- ------ 16 2147483647 1 16 2147483647 1 $x is an array of objects. First I returned the string builder, not an array.... Second the string builder is in the array twice. Huh? | ||||||||||||
My System Specs![]() | |||||||||||||
| | #2 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How does return work in powershell functions "Function Output Consists of Everything That Isn't Captured". For a deep understanding of your problem, I recommend reading Kieth Hill's Effective PowerShell posts series, start with Item 7: Understanding "Output", It has exactly what you need. http://keithhill.spaces.live.com/Blo...3A97!811.entry ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: How does return work in powershell functions "meissnersd" <meissnersd@xxxxxx> wrote in message news:09136729-2474-43E6-A302-797348A8DF9A@xxxxxx
experience when using functions in shell languages like PowerShell (or Korn shell). I have a series of blog posts that explain this issue. You can read them here: Effective PowerShell Item 7: Understanding "Output" http://keithhill.spaces.live.com/blo...3A97!811.entry Effective PowerShell Item 8: Output Cardinality - Scalars, Collections and Empty Sets - Oh My! http://keithhill.spaces.live.com/blo...3A97!816.entry -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) |
| Guest | Re: How does return work in powershell functions Thanks Keith! That was really helpful Now I will have to read the rest of your blog :-) btw I noticed the "vote for better loggin" links at the bottom of the blog were pointing to dead pages. I would add another option to vote for "typing 'help return' in powershell tells you about this issue." Documentation on this seems pretty key. Especially since it will surprise folks with programming backgrounds and since you said a lot of people post this question over and over again. |
My System Specs![]() |
| | #5 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How does return work in powershell functions "meissnersd" <meissnersd@xxxxxx> wrote in message news:393DD2C5-E368-4066-8FB4-0328E9D61E93@xxxxxx
requires logging in with a Windows Live ID (or .NET Passport ID). Then the links will work.
defects against PowerShell. If you feel particularly strongly about an issue, post a link to the newsgroup and see if you can get other folks to vote on it. -- Keith | ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: How does return work in powershell functions "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message news:4451264B-4BC4-42C1-87C4-175A450A41CF@xxxxxx
all non-captured values *unless* return statement is encountered. In that case return only what is explicitly specified. for example: function noret { 1 2 3 } returns an array of 3 values function withret { 1 2 3 return 4 } returns just the value 4 That would let the non-programmer users continue to get what they expect and allow us anal-retentive programmer types to get what we expect from it as well <g> If it's too far gone for that now then add a "returnonly" keyword that flushes the non-captured values. I can't tell you how much time I've lost tracking down bugs because something returned a value that I hadn't expected or cared about. | ||||||||||||
My System Specs![]() | |||||||||||||
| | #7 (permalink) | ||||||||||||
| Guest | Re: How does return work in powershell functions "Bob Butler" <noway@xxxxxx> wrote in message news:evBJCTGLIHA.1212@xxxxxx
like the idea of a returnonly keyword. Post on the Connect site as a suggestion and I'll vote for it. http://connect.microsoft.com -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #8 (permalink) | ||||||||||||
| Guest | Re: How does return work in powershell functions "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message news:1453305D-2E9B-4396-B98C-DF478100506F@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Return Powershell Error to VBscript | bchad | PowerShell | 1 | 06-09-2008 02:26 PM |
| Filters and Functions. Even PowerShell can't tell them apart? | Joel (Jaykul) Bennett | PowerShell | 0 | 03-23-2008 08:15 PM |
| Can Powershell return Exchange mailbox info? | Calaway | PowerShell | 5 | 01-16-2008 06:03 PM |
| Return of object with synthetic members from functions | Knut T | PowerShell | 5 | 07-07-2007 07:26 PM |
| Invoking PowerShell functions with parameters from .NET: issues. | Roman Kuzmin | PowerShell | 0 | 04-23-2007 07:35 AM |