VMSavvy
Enthusiast
Enthusiast

How to ignore local datastore..

Jump to solution

Hi LucD and other script experts,

I have a script which gives me the list of datastores, total, used and free sizes and the accessibility. This pulls out all types of datastores like local, SAN and NFS... I've taken off the NFS part.. I'm looking to see if there is a way to ignore local datastores from the list..

Attached is the script. Please help!!

Regards,

VMSavvy Smiley Happy

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Change this line

$datastores = get-vmhost  | Get-Datastore | Sort-Object Name

into this

$datastores = get-vmhost  | Get-Datastore | where {$_.Extensiondata.Summary.MultipleHostAccess} | Sort-Object Name


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership

Change this line

$datastores = get-vmhost  | Get-Datastore | Sort-Object Name

into this

$datastores = get-vmhost  | Get-Datastore | where {$_.Extensiondata.Summary.MultipleHostAccess} | Sort-Object Name


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

0 Kudos
VMSavvy
Enthusiast
Enthusiast

You are a STAR LucD... Thanks a bunch Smiley Happy Smiley Happy Smiley Happy

VMSavvy..

0 Kudos
Godwin_Christop
Enthusiast
Enthusiast

Hi Luc,

For me this{$_.Extensiondata.Summary.MultipleHostAccess} will not work, since there are some external lun connected to only one host in my Env. can you suggest some other way, thanks in Advance 🙂

0 Kudos
LucD
Leadership
Leadership

Just leave out the Where-clause


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

0 Kudos
Godwin_Christop
Enthusiast
Enthusiast

Hi Luc

I want to exclude the local datastores, can you help me with some other filter parameters that I can use. Thanks For the Response 👍  

0 Kudos
LucD
Leadership
Leadership

What is the distinction between the local datastores you want to exclude and those you want to keep?


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

0 Kudos
Godwin_Christop
Enthusiast
Enthusiast

I just want to exclude the physical hard drive that is presented as datastore1 and some other names, my actual requirement is to pull a report to validate if all the number of datastores connected to the host with the number of datastores visible on the cluster level.

foreach($vc in $global:DefaultVIServers){Get-VMHost -Server $vc | select name, Parent, @{N="Vcenter";E={$_.Uid.Split(':@')[1]}},
>> @{N="DS_Count_Vmhost";e={($_|Get-Datastore -Server $vc).count}},
>> @{N="DS_Count_Cluster";e={($_.Parent|Get-Datastore -Server $vc).count }},
>> @{N="DS";e={($_|Get-Datastore -Server $vc ) -join "|" }} | Export-Excel D:\Reports\DS.xlsx -WorksheetName $vc -Append}

here it is bringing all the local VMFS partitions, and some of them are not using the default names so filtering by name will not work for  me, if there is any other way that i can filter it with will be great

0 Kudos
LucD
Leadership
Leadership

You have to have at least one distinctive feature.
Could the Vendor or Type of these local physical drives be used?


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

0 Kudos
Godwin_Christop
Enthusiast
Enthusiast

sadly we don't have anything much, every hardware is from a different vendor. I thought there would be some parameters to isolate the local disks. 

Godwin_Christop_0-1646395839028.png

not sure if the device backing extend name will have local for all the local disk, if it does can you help me get that in script. 🙏

0 Kudos
LucD
Leadership
Leadership

Can you check if the following correctly identifies local datastores?
Is the IsLocal indication correct?

Note that the snippet only handles VMFS datastores

Get-VMHost  -PipelineVariable esx |
ForEach-Object -Process {
  $esxcli = Get-EsxCli -VMHost $esx -V2
  Get-Datastore -RelatedObject $esx -PipelineVariable ds |
  where{$_.Type -eq 'VMFS'} |
  ForEach-Object -Process {
    $ds.ExtensionData.Info.Vmfs.Extent.DiskName |
    ForEach-Object -Process {
      $esxcli.storage.core.device.list.invoke(@{device = $_ }) |
      Select @{N='VMHost';E={$esx.Name}},
        @{N='Datastore';E={$ds.Name}},
        @{N='Extent';E={$_.Device}},
        IsLocal
    }
  }
}

 


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

Godwin_Christop
Enthusiast
Enthusiast

this seems to work on a few and not on few 

WORKED
======================================================================

PS C:\> Get-VMHost bccb-dc-esx-04  -PipelineVariable esx |
>> ForEach-Object -Process {
>> $esxcli = Get-EsxCli -VMHost $esx -V2
>> Get-Datastore -RelatedObject $esx -PipelineVariable ds |
>> where{$_.Type -eq 'VMFS'} |
>> ForEach-Object -Process {
>> $ds.ExtensionData.Info.Vmfs.Extent.DiskName |
>> ForEach-Object -Process {
>> $esxcli.storage.core.device.list.invoke(@{device = $_ }) |
>> Select @{N='VMHost';E={$esx.Name}},
>> @{N='Datastore';E={$ds.Name}},
>> @{N='Extent';E={$_.Device}},
>> IsLocal}}} | ft -AutoSize
>>

VMHost Datastore Extent IsLocal
------ --------- ------ -------
bccb-dc-esx-04 BCCB-DS-01 naa.600c0ff0001e30234491245801000000 false
bccb-dc-esx-04 BCCB-DS-02 naa.600c0ff0001e3023da40225801000000 false
bccb-dc-esx-04 BCCB-DS-03 naa.600c0ff0001e30239ad0255801000000 false
bccb-dc-esx-04 BCCB-DS-04 naa.600c0ff0001e3023e6fa255801000000 false
bccb-dc-esx-04 ESXi-04 naa.600508b1001cd636a5070b7cc2cecb35 true
bccb-dc-esx-04 BCCB-DS-05 naa.600c0ff0001e355cd862ec5b01000000 false
bccb-dc-esx-04 BCCB-DS-06 naa.600c0ff0001e3023ccef9d5d01000000 false
bccb-dc-esx-04 BCCB-DS-07 naa.600c0ff0001e355cbc374c5e01000000 false
bccb-dc-esx-04 BCCB-DS-08 naa.600c0ff0001e355c7b97ad5e01000000 false
bccb-dc-esx-04 BCCB-DS-09 naa.600c0ff0001e355cf99dc95f01000000 false
bccb-dc-esx-04 BCCB-DC-SSD-11 naa.600c0ff0001e3023da1e046201000000 false

====================================================================================
Din't work

=====================================================================================

PS C:\> Get-VMHost bccb-dc-esx-07  -PipelineVariable esx |
>> ForEach-Object -Process {
>> $esxcli = Get-EsxCli -VMHost $esx -V2
>> Get-Datastore -RelatedObject $esx -PipelineVariable ds |
>> where{$_.Type -eq 'VMFS'} |
>> ForEach-Object -Process {
>> $ds.ExtensionData.Info.Vmfs.Extent.DiskName |
>> ForEach-Object -Process {
>> $esxcli.storage.core.device.list.invoke(@{device = $_ }) |
>> Select @{N='VMHost';E={$esx.Name}},
>> @{N='Datastore';E={$ds.Name}},
>> @{N='Extent';E={$_.Device}},
>> IsLocal}}} | ft -AutoSize
>>

VMHost Datastore Extent IsLocal
------ --------- ------ -------
bccb-dc-esx-07 BCCB-DS-01 naa.600c0ff0001e30234491245801000000 false
bccb-dc-esx-07 BCCB-DS-02 naa.600c0ff0001e3023da40225801000000 false
bccb-dc-esx-07 BCCB-DS-03 naa.600c0ff0001e30239ad0255801000000 false
bccb-dc-esx-07 BCCB-DS-04 naa.600c0ff0001e3023e6fa255801000000 false
bccb-dc-esx-07 BCCB-DS-05 naa.600c0ff0001e355cd862ec5b01000000 false
bccb-dc-esx-07 datastore1 naa.600c0ff0001e302325328a5d01000000 false
bccb-dc-esx-07 BCCB-DS-06 naa.600c0ff0001e3023ccef9d5d01000000 false
bccb-dc-esx-07 BCCB-DS-07 naa.600c0ff0001e355cbc374c5e01000000 false
bccb-dc-esx-07 BCCB-DS-08 naa.600c0ff0001e355c7b97ad5e01000000 false
bccb-dc-esx-07 BCCB-DS-09 naa.600c0ff0001e355cf99dc95f01000000 false
bccb-dc-esx-07 BCCB-DC-SSD-11 naa.600c0ff0001e3023da1e046201000000 false

0 Kudos
LucD
Leadership
Leadership

I was afraid of that.
You will have to use a list with the devices that are actually local to get a correct list I'm afraid.


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

0 Kudos
Godwin_Christop
Enthusiast
Enthusiast

Got That @LucD 

 

Thanks a ton 🙏, this will surely help me to exclude most of them. Thanks again.

 

Godwin_Christop_1-1647010047330.jpeg

 

0 Kudos