Hi LucD
I am using this function to unmount Datastore from multiple ESXi host
However when i run the command i get the following error
To be secure and i dont remove anything else i need to specify the cluster as well
#########################################
get-datastore CLUSTER227_003_NR | Unmount-Datastore
###########################################
Error
Get-View : 8-7-2022 13:28:02 Get-View Object reference not set to an instance of an object.
At line:98 char:18
+ $hostview = Get-View $VMHost.Key
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands
.DotNetInterop.GetVIView
Get-View : 8-7-2022 13:28:02 Get-View View with Id 'HostSystem-host-8168' was not found on the server(
s).
At line:98 char:18
+ $hostview = Get-View $VMHost.Key
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_GetView_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Comma
nds.DotNetInterop.GetVIView
Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an a
rgument that is not null or empty, and then try the command again.
At line:99 char:29
+ ... $StorageSys = Get-View $HostView.ConfigManager.StorageSystem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Comm
ands.DotNetInterop.GetVIView
Unmounting VMFS Datastore CLUSTER227_003_NR from host ...
You cannot call a method on a null-valued expression.
At line:101 char:6
+ ... $StorageSys.UnmountVmfsVolume($DS.ExtensionData.Info.vmfs ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Get-View : 8-7-2022 13:28:02 Get-View Object reference not set to an instance of an object.
At line:98 char:18
+ $hostview = Get-View $VMHost.Key
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands
.DotNetInterop.GetVIView
Get-View : 8-7-2022 13:28:02 Get-View View with Id 'HostSystem-host-8342' was not found on the server(
s).
At line:98 char:18
+ $hostview = Get-View $VMHost.Key
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-View], VimException
+ FullyQualifiedErrorId : Core_GetView_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Comma
nds.DotNetInterop.GetVIView
Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an a
rgument that is not null or empty, and then try the command again.
At line:99 char:29
+ ... $StorageSys = Get-View $HostView.ConfigManager.StorageSystem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Comm
ands.DotNetInterop.GetVIView
Please help
Many thanks
RXJ
That is what the Unmount-Datastore function does, it unmounts the datastore from all ESXi nodes that have it mounted.
You will have to change the function if you only want the unmount to happen on a specific ESXi node.
Something like this
$esxName = 'MyEsx'
$dsName = 'MyDS'
$ds = Get-Datastore -Name $dsName
$esx = Get-VMHost -Name $esxName
$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem
$storSys.UnmountVmfsVolume($ds.ExtensionData.Info.vmfs.uuid)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It looks like that datastore is connected to an ESXi node that is not found in the vCenter you are currently connected to.
Just to make sure that datastore is actually named 'CLUSTER227_003_NR'?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I sorted its working thanks
I have another query because I am decommissioning ESXi host and I want to make sure i remove only the correct Luns from the Cluster which is subject to decom
The below query works but it dosent remove only from the specified ESXi host, it removes from all ESXi host
I need to be able to remove from specified ESXi host
How to do that please
$xDS = import-csv -Path E:\RXJ\DecomDS.csv
foreach ($DcomDS in $xds ) {
get-cluster Cluster109_SQL |get-vmhost xxx01018..example.com |get-datastore $DcomDS.Ds_name |Unmount-Datastore
}
Many thanks
RXJ
That is what the Unmount-Datastore function does, it unmounts the datastore from all ESXi nodes that have it mounted.
You will have to change the function if you only want the unmount to happen on a specific ESXi node.
Something like this
$esxName = 'MyEsx'
$dsName = 'MyDS'
$ds = Get-Datastore -Name $dsName
$esx = Get-VMHost -Name $esxName
$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem
$storSys.UnmountVmfsVolume($ds.ExtensionData.Info.vmfs.uuid)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD
really appreciate your help