I have a script which makes use of the Get-Disk command in Powershell. Intermittently, I get an error when using Get-Disk with no parameters:
$disk = Get-Disk | Where-Object { $_.Location -eq $Location }
Microsoft.Management.Infrastructure.CimException: Invalid property
at Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
where $Location
is the disk location (similar to PCIROOT(0)#PCI(1500)#PCI(0000)#SAS(P00T01L00)
). The script this line is run from is part of our VM provisioning script, which gets run after the clone and VMWare customization script is run. This error does not always happen, and if I go and run the script manually later it succeeds every time leading me to believe it is a race condition of some sort. Any ideas as to why Get-Disk isn't working reliably?
Ultimately, this script is being kicked off from vRealize Orchestrator (vRO, formerly vCenter Orchestrator or vCO) using the Guest Script Manager
plugin. This detail may not be relevant, but this script has only failed running when kicked off by this plugin.
Additional details:
I ended up provisioning the disks with diskpart instead of the storage cmdlets, which works without issue. Although I did find out that our script is running while the Windows installation is still completing, which may account for the storage cmdlets not working properly.
Follow Up: I did confirm that the storage cmdlets were indeed not working due to the Windows installation still completing. Now that I figured out how to wait for completion, the storage cmdlets work fine every time.