Many months ago I wrote a script to gather some information on our VMWare environment, part of which included getting information about the datastores. I used Get-datastore to do this.
Today, I updated my PowerCLI version from 4.something to the latest, 5.0.1 and now when I run Get-Datastore I receive an error message "object reference not sent to an instance of an object." The error references line 14 of the cmdlet. What gives? This worked fine up until I moved to the latest version of the powerCLI. Our vSphere environment is 5.0, so my understanding is this is supported. I've tried get-datastore with every parameter I can think of, from specifying the name of the datastore to connect to, to giving the name of the host or guest I want to get the datastores from. Each time it results in the same error as above. I can't even pass get-datastore to get-member without receiving that error! Any ideas?
This is very strange indeed, the only thing I can think is that PowerCLI didnt install correctly, is it possibe to try this from another machine with 5.0.1 please?
Alan -
Thanks for the reply. I should have mentioned in my initial post that I did try it on another computer, in fact, I tried it on one with a completely different OS. This is happening to me on a Windows 7 and Windows 2008 system. I've been trying to find a powercli 4.x download to revert to and see what happens, but so far no luck.
The only thing I can think of is that our setup of vSphere is somehow the wrong version or mis-configured. Interestingly, the other commands I use (get-datacenter, get-vm, get-vmhost, etc) all work without a hitch!
Versions should be fine, are all your hosts vSphere 5 as well or are they a mixed version ?
What happens when you do a:
Get-View -ViewType Datastore
You can confirm if any refresh should cause the error too. Any remediate has been executed recently?
What happens when executing a simple task like "Get-Datastore -vm MyVM" ?
Hi,
can you provide information on the error like:
Get the error from $error ($e = $error[0] if that was the last error). Do a:
$e.Exception | select *
$e.Exception.InnerException | select *
and provide the result here.
Alan - All of the hosts I'm working with are vSphere 5.0.0. Running the command you provided returns a slew of information about the datastores without error.
GuilhermeStela - No matter what parameters I feed Get-Datastore I receive the error message. I've tried -VM, -VMHost, -DataCenter, etc...always the same error.
AtanasAtanasov - Here is the error information:
ErrorId : Core_BaseCmdlet_UnknownError
ErrorCategory : NotSpecified
TargetObject :
RecommendedAction :
SessionId :
Severity : Error
Message : 4/27/2012 7:47:07 AM Get-Datastore 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.Impl.V1.Service.DatastoreServiceImpl.GetDatacenterDatastoreList()
at VMware.VimAutomation.ViCore.Impl.V1.Service.StorageServiceImpl.<GetDatastoreStream>d__0.MoveN
ext()
at VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastoreWorker.DoWork(List`1 moList)
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.CmdletWorker.DoWork(List`1 moList)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.CmdletWorker.StartWork(Object obj)
TargetSite :
StackTrace :
HelpLink :
Source :
And the InnerException info:
Message : Object reference not set to an instance of an object.
Data : {}
InnerException :
TargetSite : System.Collections.Generic.Dictionary`2[System.String,VMware.VimAutomation.ViCore.Interop.V1.VIObjectI
nterop] GetDatacenterDatastoreList()
StackTrace : at VMware.VimAutomation.ViCore.Impl.V1.Service.DatastoreServiceImpl.GetDatacenterDatastoreList()
at VMware.VimAutomation.ViCore.Impl.V1.Service.StorageServiceImpl.<GetDatastoreStream>d__0.MoveNext
()
at VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastoreWorker.DoWork(List`1 moList)
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.CmdletWorker.DoWork(List`1 moList)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.CmdletWorker.StartWork(Object obj)
HelpLink :
Source : VMware.VimAutomation.ViCore.Impl
I was able to find an old version of PowerCLI, 4.1.1-332441 to be exact, and Get-Datastore works just fine in that version. I also found and tried PowerCLI version 4.0.1 and it had the same problem as version 5.0 did...weird.