Hello,
I recently wrote a script with the help of LucD to be able to scan a vCenter if it has multiple datacenters or not. If it has more than 1 it prompts to choose, if not then the script moves forward. In this instance I'm having an issue when there's more than 1 datacenter. For whatever reason it works fine on my vCenter (6.5), but when running on a 6.0 vCenter it throws up an error, but still completes. PowerCLI version is 10.1.1 on the machine I test on and the one that the script is being run from. Both are Windows 10 RS4 and have PowerShell 5.1 as well. Below is the error:
Get-Cluster : 11/15/2018 4:29:24 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by
name.
At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33
+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O
bnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore
.Cmdlets.Commands.GetCluster
Get-Cluster : 11/15/2018 4:29:25 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by
name.
At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33
+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O
bnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore
.Cmdlets.Commands.GetCluster
Get-Cluster : 11/15/2018 4:29:25 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by
name.
At C:\Users\admin\Desktop\GenSeriallyMigrateFromHostToHost.ps1:44 char:33
+ Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Tabl ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], O
bnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore
.Cmdlets.Commands.GetCluster
Below is the initial code, where the last line is line 44 that's referenced in the error:
$commands = { #This is the top of the loop, if you hit C at the end of the script it will take you back here
$dc = Get-Datacenter #This gets the datacenters, if more than 1 it will ask you which one to choose, if only one it will move forward in the script
if ($dc.Count -gt 1) {
Write-Host "I found $($dc.Count) datacenters"
Write-Host "Choose a datacenter"
1..($dc.Count) | %{
Write-Host "$_ - $($dc[$_ - 1].Name)"
}
$answer = 0
while (1..($dc.Count) -notcontains $answer){
$answer = Read-Host -Prompt "Select a datacenter (1-$($dc.Count))"
}
}
Get-Datacenter -Name $dc.Name | Get-Cluster | sort Name | Format-Table #Gets the clusters in the datacenter
So is it something that needs to be changed somehow to accommodate different vCenter versions? I thought this script would work pretty well between versions of vCenter/ESXi. Is there that much of a difference? I'm tempted to build my own setup that has 6.0, 6.5 and 6.7 just to see how differently the scripts behave.