Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've just started in the world of Powershell and I'm writing a simple script to put hosts in maintenance mode, apply patches, reboot, then put back into server. I decided to use the failover clustering service to check the host's availability before placing back into service. But I seem to be getting an error which I can't find much about.

Get-ClusterNode : Cannot convert '' to the type     'System.Collections.Specialized.StringCollection' required by parameter 'Name'. Unable to cast object of type 'System.Management.Automation.PSObject' to type 'System.String'.

The Code I have is:

$VMMServer = Get-VMMServer -ComputerName ""
$Cluster = "HyperVCluster"
$VMHosts = Get-VMHost -VMHostCluster $Cluster
Foreach ($VMHost in $VMHosts) {
psexec \\$VMHost -s wuinstall /reboot /install
sleep 120
$Status = Get-Clusternode -Cluster $Cluster -name $VMHost | select state
function CheckHostStatus {
if ($Status -match "Up") {
Write-Host "Host is Up"
Write-Host "Placing host" $VMHost "back into service."
    Enable-VMHost $VMHost
elseif ($Status -match "Down") {
Write-Host "Host is still rebooting"
sleep 120
share|improve this question
up vote 0 down vote accepted

Get-VMHost returns "VMHost[]" as a type.

So each VMHost returned is a custom, structured type, not a simple string.

My understanding is that the VM-Host structure is as such (I don't have the PS VM add-ons installed here to double check):

  • State
  • CustomFields
  • ID
  • Name

So perhaps try using $VMHost.Name when you just want the (string) name of the current VMHost:

$Status = Get-Clusternode -Cluster $Cluster -name $VMHost.Name | select state

Write-Host "Placing host " + $VMHost.Name + " back into service."

share|improve this answer
Thank you very much, this solved my problem. I'm still confused as to why all the other times I reference $VMHost have no issue. – user96596 Sep 4 '11 at 20:29
Glad it helped! :) As to your (understandable) confusion: If it knows for sure you want a string (ie: in a Write-Host) it pulls the name as the generic 'string' representation of the object. But if the required type is unclear (which often happens when using Vars in parameters) it returns it as the whole (structured) object, so you have to specifically tell it you want the Name property. – Ƭᴇcʜιᴇ007 Sep 4 '11 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .