I went ahead and created three simple functions that were supposed to help me understand how things work and how I can use them in the future.
function Set-HashTable {
param(
[System.Collections.IDictionary] $Hash,
[string] $Property,
[Object] $Value
)
$Hash.$Property = $Value
# no return values
}
function Set-CustomObject {
param(
[PsCustomObject] $Custom,
[string] $Property,
[Object] $Value
)
$Custom.$Property = $Value
# no return values
}
function Set-CustomInt {
param(
[int] $MyInt,
[int] $Value
)
$MyInt = $Value
}
I've then defined three variables. One int, one PSCustomObject, and one HashTable.
Now I simply overwrite those values by using the first static assignment and then updating each variable inside a function.
Can you guess what above code returns? I'll leave it up to you, but till a few days ago I've always assumed that when I pass a variable to a function to get it back, I've to return it. So when I pass a HashTable, and I want to get it back I would return full HashTable and assign it back to either new variable or to the same variable I've passed to function. But the way it works above (and the code above proves it) you can pass HashTable to a function, update its values and get it back without assigning anything back. Isn't it cool? I know you're probably saying YOU NOOB everyone knows it! Well, I didn't know. But that's how I roll. Only hardcore stuff, basics are for losers right? Till they bite you hard! So learn from my mistakes and read the documentation before jumping in, you may save yourself time later on!