StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell
SMB
VBScript

PowerShell: Returning a value from a function

Saturday, June 22, 2013 in Powershell (Views: 2623)
One thing I learned early in learning PowerShell: Don't be like TechNet, where the blog header leads to a mile long answer leaving you wanting the actual answer.

The lesson, how do you actually return something from a function?
Well, simple as this (let's use the last blog example):
Function WriteSomething {param([string]$a, [string]$b)
return $a $b
}


The key here, of course, is the return.

How do you call it? Simple. Now, those used to VBScript are in for a little culture shock, but parameters are separated by spaces, not commas. So, you call it as such:

$tempString=WriteSomething Hello World
write-host $tempString

Returns: Hello World

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.