So if I have the following code:
function DoSomething {
$site = "Something"
$app = "else"
$app
return @{"site" = $($site); "app" = $($app)}
}
$siteInfo = DoSomething
$siteInfo["site"]
Why doesn’t $siteInfo[“site”] return “Something”?
I can state just….
$siteInfo
And it will return
else
Key: site
Value: Something
Name: site
Key: app
Value: else
Name: app
What am I missing?
In PowerShell, functions return any and every value that is returned by each line in the function; an explicit
returnstatement is not needed.The
String.IndexOf()method returns an integer value, so in this example,DoSomethingreturns ‘2’ and the hashtable as array of objects as seen with.GetType().The following example shows 3 ways to block unwanted output:
Here is an example of how to wrap multiple statements in a ScriptBlock to capture unwanted output: