1

Why doesn't the below code print the object values when passed into a function? what am I missing?

$Name=@{}
$Name.firstName="John"
$Name.lastName="Doe"

$NameObj=new-object psobject -property $Name


function GetName([PSObject]$NameObj) {
    $NameObj
}

GetName

1 Answer 1

1

You have to pass the value to the GetName function:

GetName $NameObj
Sign up to request clarification or add additional context in comments.

3 Comments

It is so embarrassing, it missed my eye.
The name of the function is actually fine and does not need to be corrected. There are PowerShell Style Guides that recommend using the Verb-Object naming for advanced functions and camel cases for simple functions like the one above.
@ManuelBatsching I didn't know that, thanks for mentioning and providing the link. I removed that comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.