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 'hyperv1.example.com' 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 "scvmm.example.com"
$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
CheckHostStatus
}
}
CheckHostStatus
}