greetings, folks ---
my Requirement: in order to make sure that all VMs actually get migrated off the host when I place the host in maint mode -- I would like a validation check across all the VMs in the datacenter through powercli
my question is can we run just that part which shows us whether a VM is vmotionable or not when we do it thru the VC ....? that is for example - if we try to migrate a VM which has its VLAN missing in the destination farm we get in that in the GUI .......
thanks!!
~Sai Garimella
anyone?
Hello, SG1234-
Man, LucD was at VMworld Barcelona this week -- you gots to have patience!
I had a look, and it appears that you can use the QueryVMotionCompatibilityEx_Task method of the VirtualMachineProvisioningChecker object (which is a property of the ServiceContent object).
So, a quick example:
## name of VM to check for VMotion compatibility
$strMyVMNameToCheck = "myVM0"
## name of destination VMHost to check for VMotion compatibility for this VM
$strMyVMHostNameToCheck = "myDestinationHost.mydomain.com"
## get the ServiceInstance object
$viewSI = Get-View 'ServiceInstance'
## get the VMProvisioningChecker object
$viewVmProvChecker = Get-View $viewSI.Content.VmProvisioningChecker
## query the VMotion Compatibility
$viewVmProvChecker.QueryVMotionCompatibilityEx((Get-VM $strMyVMNameToCheck).Id, (Get-VMHost $strMyVMHostNameToCheck).Id)
This returns a VMware.Vim.CheckResult object that has an Error and a Warning property that would be populated if the vMotion is going to possibly be problematic.
You can then, from the example, see how to perform such a check for all VMs on a host, for a VM to all other hosts in a cluster, etc -- whatever you can think up.
How does that treat you?
Thanks Matt, next time I'll remember to put an OOO up here
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks -- need to loop through all the VMs in the cluster ...and check for all the hosts - I am hopeful that I can create loops on my own
Thanks !
~Sai Garimella
The loops should be quite simple.
This should give you an idea.
$clusterName = "MyCluster"
$cluster = Get-Cluster -Name $clusterName
$hypervisors = Get-VMHost -Location $cluster
$vms = Get-VM -Location $cluster
foreach($vm in $vms){
# Get the settings to check for this VM
...
foreach($esx in $hypervisors){
# Check the settings in each ESXi
...
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD wrote:
Thanks Matt, next time I'll remember to put an OOO up here
Ha, yeah, you need to set peoples' service level expectations! They see "LucD, OoO", they probably won't even post until you return...
I am new to scripting... I've tried the below script but Its erroring out. Please help.
$SourceVMs = "D:\VMs.txt"
$list = Get-Content $SourceVMs | Foreach-Object {Get-VM $_ }
foreach ($item in $list)
{
$VM = $item.Name
## get the ServiceInstance object
$viewSI = Get-View "ServiceInstance"
$viewVmProvChecker = Get-View $viewSI.Content.VmProvisioningChecker
$viewVmProvChecker.QueryVMotionCompatibilityEx((Get-VM $VM).Id, (Get-VMhost XXXXX.com).Id) | Export-Csv "D:\VmComp.csv"
}
Errors:
$SourceVMs = "D:\VMs.txt"
$list = Get-Content $SourceVMs | Foreach-Object {Get-VM $_ }
foreach ($item in $list)
{
$VM = $item.Name
## get the ServiceInstance object
$viewSI = Get-View "ServiceInstance"
$viewVmProvChecker = Get-View $viewSI.Content.VmProvisioningChecker
$viewVmProvChecker.QueryVMotionCompatibilityEx((Get-VM $VM).Id, (Get-VMhost ausesxi-158.amd.com).Id) | Export-Csv "D:\VmComp.csv"
}
I made some changes. Can you try this:
## get the ServiceInstance object $viewSI = Get-View "ServiceInstance" $viewVmProvChecker = Get-View $viewSI.Content.VmProvisioningChecker $strMyVMHostNameToCheck = "ausesxi-158.amd.com" $VMHost = Get-VMHost -Name $strMyVMHostNameToCheck $SourceVMs = "D:\VMs.txt" $list = Get-Content $SourceVMs | Foreach-Object {Get-VM $_ } & {foreach ($VM in $list) { $viewVmProvChecker.QueryVMotionCompatibilityEx($VM.Id, $VMHost.Id) } } | Select-Object @{N="VM";E={($_.Vm | Get-VIObjectByVIView).Name}}, @{N="VMHost";E={($_.Host | Get-VIObjectByVIView).Name}}, @{N="Warning";E={[string]::Join(',',$_.Warning)}}, @{N="Error";E={[string]::Join(',',$_.Error)}}, LinkedView, DynamicType, DynamicProperty | Export-Csv -Path "D:\VmComp.csv" -NoTypeInformation -UseCulture
I removed everything that needs only to be done once out of the loop. The new script returns the names of the vm and the host instead of the MoRef. The warning and error properties are arrays. The [string]::Join method creates strings out of these arrays. The &{ before foreach is needed because you pipe the output into a cmdlet.
Thanks Rob. It worked.
Is there a way to include the failure details. Like CPU Compatibility and Storage.
To get the failure details you can change the lines:
@{N="Warning";E={[string]::Join(',',$_.Warning)}}, @{N="Error";E={[string]::Join(',',$_.Error)}},
into:
@{N="Warning";E={[string]::Join(',',$_.Warning.LocalizedMessage)}}, @{N="Error";E={[string]::Join(',',$_.Error.LocalizedMessage)}},
Again thanks for your time. this returned blanks for Errors and Warning field. Let me try it to get it workd.
Thanks
When I tried the above script it was giving Warning and Errors as "VMware.Vim.LocalizedMethodFault".
Hence, I used
@{N="Warning";E={[string]::Join(',',$_.Warning.LocalizedMessage)}},
@{N="Error";E={[string]::Join(',',$_.Error.LocalizedMessage)}},
But this was giving blanks.
Can we try to get the actual warning and errors messages. Please help.
If these fields are blank that would mean that vSphere sees no problems in a vMotion of the VM to the specific host.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks so much for replying LuCD . But the vMotoin indeed have come CPU compatibility issue and some VMs have connected CD drive
When I run with these lines
@{N="Warning";E={[string]::Join(',',$_.Warning)}},
@{N="Error";E={[string]::Join(',',$_.Error)}},
Output is
"VM","VMHost","Warning","Error","LinkedView","DynamicType","DynamicProperty"
"TestVM01","ESXhost1.internal.com",,"VMware.Vim.LocalizedMethodFault,VMware.Vim.LocalizedMethodFault",,,
When I run with these lines
@{N="Warning";E={[string]::Join(',',$_.Warning.LocalizedMessage)}},
@{N="Error";E={[string]::Join(',',$_.Error.LocalizedMessage)}}
Output is
"VM","VMHost","Warning","Error","LinkedView","DynamicType","DynamicProperty"
"TestVM01","ESXhost1.internal.com",,,,,
Afaik that doesn't say there are messages available in those properties.
In the first attempt, the output engine will display the type of the nested property, since it doesn't know how to display the object.
The 2nd attempt should give you the text, provided there is any.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks so much once again for replying.
You are true, it should receive localizedMessage. However, the text is not getting displayed irrespective of any warning or error.
When I migrate the VM, I receive this message which says there is Connected device.
Move-VM : 8/20/2013 2:41:17 AM Move-VM The operation for the entity VirtualMachine-vm-27421 failed with the following message:
"Currently connected device 'CD/DVD Drive 1' uses backing '[] /vmimages/tools-isoimages/linux.iso', which is not accessible."
At C:\Scripts\Testing\4.ps1:45 char:40
+ Get-VM -Location $SourceHName | Move-VM <<<< -Destination (Get-Vmhost $DestHName) | Export-Csv $attach -NoTypeInformation -UseCulture
+ CategoryInfo : NotSpecified: (:) [Move-VM], CannotAccessVmDevice
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Co
mmands.MoveVM
Can't we receive such messages or texts which is easily readable.
Perhaps try it like this
@{N="Warning";E={[string]::Join(',',($_.Warning | %{$_.LocalizedMessage}))}},
@{N="Error";E={[string]::Join(',',($_.Error | %{$_.LocalizedMessage}))}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome !!! It works. You are a champ
Thank you so much!!