icontrolyourpow
Enthusiast
Enthusiast

Get-VIObjectByVIView broken?

powercli_41.jpgpowercli_4.jpg

The documentation leads me to believe piping the view object or passing it via the -viview parameter should work. Am I missing somethng or is this broken?

0 Kudos
5 Replies
LucD
Leadership
Leadership

I can confirm what you are seeing, I have the same problem.

Seems to be related to the cmdlet not being able to pull out the MoRef property.

Because this doesn't work

$vm = Get-VM MyVM | Get-View

Get-VIObjectByView $vm

But this does work

$vm = Get-VM MyVM | Get-View

Get-VIObjectByView $vm.MoRef


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

0 Kudos
ykalchev
VMware Employee
VMware Employee

Hi,

Can you post exception stacktrace of the error since I wasn't able to reproduce the issue.

Any specific ESX/VC version?

Thanks,

Yasen

Yasen Kalchev, vSM Dev Team
0 Kudos
LucD
Leadership
Leadership

Yasen, I did the following

$vm = Get-View -ViewType VirtualMachine -Filter @{"Name"="MyVM"}

Get-VIObjectByVIView -VIView $vm

That throws the error.

PS C:\> Get-VIObjectByVIView -VIView $vm
Get-VIObjectByVIView : 31-01-2011 13:52:24    Get-VIObjectByVIView        Object reference not set to an instance of an object.
At line:1 char:21
+ Get-VIObjectByVIView <<<<  -VIView $vm
    + CategoryInfo          : NotSpecified: (:) [Get-VIObjectByVIView], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIObjectByVIViewCommand

PS C:\> $error[0].Exception | select *


ErrorId           : Core_BaseCmdlet_UnknownError
ErrorCategory     : NotSpecified
TargetObject      :
RecommendedAction : Error occured while executing cmdlet: Get-VIObjectByVIView. Check inner exception for more details.
SessionId         :
ConnectionId      :
Severity          : Error
Message           : 31-01-2011 13:52:24    Get-VIObjectByVIView        Object reference not set to an instance of an object.
Data              : {ParameterValues}
InnerException    : System.NullReferenceException: Object reference not set to an instance of an object.
                       at VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIObjectByVIViewCommand.CreateClientFromView(ViewBase view, Uri
                     serverUri)
                       at VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIObjectByVIViewCommand.GetClientByVIView(ViewBase view, IDicti
                    onary`2 viewConnectionIdList)
                       at VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIObjectByVIViewCommand.GetMoListFromCmdletParameter(IList`1& m
                    oList, String& parameterName, Boolean& isServerParameterObnOnly)
                       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
                       at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()
TargetSite        : Void ThrowTerminatingError(System.Management.Automation.ErrorRecord)
StackTrace        :    at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
HelpLink          :
Source            : System.Management.Automation

Note that this works without a problem

PS C:\> Get-VIObjectByVIView -MORef $vm.MoRef

Name                 PowerState Num CPUs Memory (MB)
----                          ----------       --------        -----------
MyVM                 PoweredOn               2              4096

This is with PowerCLI 4.1U1 against a vCenter 4.1.0 build 258902 with ESX 4.1.0 build 320092.


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

0 Kudos
internetrush1
Contributor
Contributor

Get-VIObjectByVIView : 4/29/2013 1:13:49 PM    Get-VIObjectByVIView        Object reference not set to an instance of an object.   
At line:1 char:21
+ Get-VIObjectByVIView <<<<  -MORef ($VmVIew.moref)
    + CategoryInfo          : NotSpecified: (:) [Get-VIObjectByVIView], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIObjectByVIViewCommand

Name                 PowerState Num CPUs Memory (MB)
----                 ---------- -------- -----------
ntapth3890m00        PoweredOn  4        10240    

LucD, confirmed that your version does work, but throws an exception as well.

Do you have clarification why this does not work as expected?

Running PowerCLI 5.1 with ESXi 5.1     

0 Kudos
LucD
Leadership
Leadership

Just tried it, in PowerCLI 5.1 R1 the problem is apparently not there anymore


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

0 Kudos