PowerShell 7.3 - scenarios with Custom Function Returning Object Type Instead of Expected String
Does anyone know how to I'm working on a personal project and I'm working on a personal project and I'm currently working on a custom PowerShell function that is supposed to return a formatted string, but instead, it's returning an object type, which is causing issues when I try to concatenate it with other strings. The function is designed to take a list of user names and return a greeting message for each. Here's the code I'm using: ```powershell function Get-Greeting { param ( [string[]]$UserNames ) $greetings = foreach ($name in $UserNames) { "Hello, $name!" } return $greetings } $userList = @('Alice', 'Bob', 'Charlie') $result = Get-Greeting -UserNames $userList ``` When I print `$result`, I expect to see a string with greetings formatted like 'Hello, Alice! Hello, Bob! Hello, Charlie!'. However, I get an array of strings instead. If I try to concatenate it like so: ```powershell $finalMessage = "Greetings: " + $result ``` I end up with an output that looks like this: ``` Greetings: System.Object[] ``` I attempted to use the `-join` operator to combine the elements of the array into a single string, like this: ```powershell $finalMessage = "Greetings: " + ($result -join ' ') ``` However, the output still doesn't look quite right, as it's not properly formatted with line breaks or commas as I would prefer. What am I doing wrong? Is there a better way to structure the output of the `Get-Greeting` function to achieve the desired format? Any assistance would be greatly appreciated! This is part of a larger web app I'm building. What am I doing wrong? This issue appeared after updating to Powershell 3.9. I've been using Powershell for about a year now. Thanks in advance!