I’m struggling to figure what am I doing wrong on this one…
I’m fairly new to Powershell scripting and I’m creating a function to get me the virtual machine current host. So far, so good, but…! I’m creating a new object (pretty simple one), but my ComputerName value is returning inside {}. Look at the code:
You allow for the $ComputerName in your param block to be an array of strings [String]. So your variable $ComputerName will likely be an array. Therefor the output will be an array as well. So you should change the variable type in your param block to a single string [String].
If you are using VMWare, the PowerCLI has cmdlet for this. Get-VMHost -VM <VMName> will return the host details for that VM. This cmdlet supports array of VMs, so a oneliner would be enough.