VMware Cloud Community
dloop2
Contributor
Contributor
Jump to solution

Get-View behavior

The following code will work in our Lab VMWare environment, but not in our Test VMware environment.

Get-Cluster | % {

Write-Host "Cluster:" $_.Name

Write-Host "ID:" $_.ID

Get-View $_.ID

}

When it fails in our test environment, it fails with the Get-View statement (similar to another thread here). Here is the error

The request refers to an object that no longer exists or has never existed.

at line XX, position 13

Get-View $_.ID

Both environments are running VC 2.5 update 1. The Lab environment is all ESX 3.5, the Test environment is all ESX 3.02.

When I step through the code, jsut prior to the "Get_View" statement, $_.ID is not null. It appears to have a valid ID value.

So why would Get-View not work the same in both environments?

Reply
0 Kudos
1 Solution

Accepted Solutions
ykalchev
VMware Employee
VMware Employee
Jump to solution

This strange bevavior is caused by a limitation of Get-View cmdlet in the beta. It use the first connected VIServer to query for the objects. For example:

Get-VIServer LabHost

Get-Cluster | % {

Write-Host "Cluster:" $_.Name

Write-Host "ID:" $_.ID

Get-View $_.ID }

Get-View will query LabHost for the object - everything is OK

Get-VIServer TestHost

Get-Cluster | % {

Write-Host "Cluster:" $_.Name

Write-Host "ID:" $_.ID

Get-View $_.ID -

Here Get-View will query LabHost again for the cluster ID located in TestHost server and returns error

So be carefull using Get-View with multiple connections. Try to run the script for each server in a new PS console to find out is this is the real problem.

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The Get-View cmdlet should work with clusters composed of ESX 3.0.2 hosts and with clusters composed of ESX 3.5 hosts.

Can you get to the cluster with the Managed Object browser (https:///mob) in both environments ?

Does the ID you get in the script correspond with the one you see in the MOB ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

ykalchev
VMware Employee
VMware Employee
Jump to solution

This strange bevavior is caused by a limitation of Get-View cmdlet in the beta. It use the first connected VIServer to query for the objects. For example:

Get-VIServer LabHost

Get-Cluster | % {

Write-Host "Cluster:" $_.Name

Write-Host "ID:" $_.ID

Get-View $_.ID }

Get-View will query LabHost for the object - everything is OK

Get-VIServer TestHost

Get-Cluster | % {

Write-Host "Cluster:" $_.Name

Write-Host "ID:" $_.ID

Get-View $_.ID -

Here Get-View will query LabHost again for the cluster ID located in TestHost server and returns error

So be carefull using Get-View with multiple connections. Try to run the script for each server in a new PS console to find out is this is the real problem.

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
Reply
0 Kudos
dloop2
Contributor
Contributor
Jump to solution

That was it. Thank you.

Reply
0 Kudos