Automation

 View Only
Expand all | Collapse all

finding missing datastore _powercli

  • 1.  finding missing datastore _powercli

    Posted Oct 24, 2017 06:36 PM

    hi Luc,

    could you check the following output and suggest some way to find missing datastores.

    i run following .

    get-cluster "cluster name"|get-vmhost|%{write-output "datastorecount on $($_.name) is $(($_.extensiondata.datastore).count)"}

    output is

    datastorecount on 4h.shdc.chrysler.com is 195

    datastorecount on 4i.shdc.chrysler.com is 195

    datastorecount on 4j.shdc.chrysler.com is 195

    datastorecount on 4k.shdc.chrysler.com is 194

    datastorecount on 4f.servers.chrysler.com is 195

    datastorecount on 4g.servers.chrysler.com is 195

    datastorecount on 4c.servers.chrysler.com is 194

    datastorecount on 4d.servers.chrysler.com is 194

    datastorecount on 4e.servers.chrysler.com is 194

    datastorecount on 4b.servers.chrysler.com is 194

    datastorecount on 4a.servers.chrysler.com is 194

    datastorecount on 4m.shdc.chrysler.com is 196



  • 2.  RE: finding missing datastore _powercli
    Best Answer

    Posted Oct 25, 2017 12:38 PM

    Try something like this

    $cluster = Get-Cluster MyCluster

    $dsNames = (Get-Datastore -RelatedObject $cluster).Name

    Get-VMHost -Location $cluster | where{$_.DatastoreIdList.Count -ne $dsNames.Count} |

    Select Name,

        @{N='Cluster DS Count';E={$dsNames.Count}},

        @{N='ESXi DS Count';E={$_.DatastoreIdList.Count}},

        @{N='Missing DS';E={

            $script:dsEsx = (Get-View -Id $_.DatastoreIdList -Property Name).Name

            ($dsNames | where{$script:dsEsx -notcontains $_}) -join '|'}}



  • 3.  RE: finding missing datastore _powercli

    Posted Oct 25, 2017 01:49 PM

    ThnaksLuc,

    could you explain following line

    @{N='Missing DS';E={

            $script:dsEsx = (Get-View -Id $_.DatastoreIdList -Property Name).Name

            ($dsNames | where{$script:dsEsx -notcontains $_}) -join '|'}}

    also is there any property in get-datastore command that differentiate between local and SAN datasotre.

    i initially thought of filter out local datastore first using where clause and then using compare-object command to comare exported files from each esxi.



  • 4.  RE: finding missing datastore _powercli

    Posted Oct 25, 2017 04:02 PM

    Sure, when you get the datastores for a cluster, you get all the datastores, even the ones that are not attached to one or more of the ESXi nodes in that cluster.

    I collect these names in the array $dsNames.

    For each ESXi node I get the names of all the datastores that this ESXi node knows.

    Then I compare that list of names with the list of names known cluster-wide.

    Yes, you can check the value of $ds.ExtensionData.Summary.MultipleHostAccess

    If that is $false, it is a local datastore



  • 5.  RE: finding missing datastore _powercli

    Posted Oct 25, 2017 04:47 PM

    i just tried to check compare options just for one esxi host .

    $cluster = Get-Cluster shc004

    $dsNames = (Get-Datastore -RelatedObject $cluster).Name

    $script:dsEsx=Get-Datastore -vmhost "shc004k.shdc.chrysler.com"

    $dsnames|Where-Object{$script:dsesx -notcontains $_}

    i have two questions:

    1:  $_       is nothing but $dsnames is this correct?

    2:running above the four line code will give the missing datastore in 4k node but it is not happening.

    i have been using where-object to check conditions on some properties but in above you comapred two variables $script:dsesx and  $dsNames .i did not know that.



  • 6.  RE: finding missing datastore _powercli

    Posted Oct 25, 2017 05:56 PM

    The script is in fact taking the first array, and feeding it to the pipeline.

    Then each array element (the $_, or the object in the pipeline), is checked (-notcontains) if it is present in the other array.

    If the array element ($_) passes the Where-clause, then it is an array element that was not present in the other array.



  • 7.  RE: finding missing datastore _powercli

    Posted Oct 25, 2017 06:10 PM

    Thanks very much Luc.appreciate your help.



  • 8.  RE: finding missing datastore _powercli

    Posted Jun 09, 2020 01:59 AM
    Handy script but what if I have 20 hosts and they all show the local disk?  How would I filter out "Local"? 


  • 9.  RE: finding missing datastore _powercli

    Posted Jun 09, 2020 05:37 AM

    You can use the MultipleHostAccess property to filter local datastores out.

    $cluster = Get-Cluster MyCluster

    $dsNames = (Get-Datastore -RelatedObject $cluster | where{$_.ExtensionData.Summary.MultipleHostAccess}).Name


    Get-VMHost -Location $cluster | where{$_.DatastoreIdList.Count -ne $dsNames.Count} |

    Select Name,

        @{N='Cluster DS Count';E={$dsNames.Count}},

        @{N='ESXi DS Count';E={$_.DatastoreIdList.Count}},

        @{N='Missing DS';E={

            $script:dsEsx = (Get-View -Id $_.DatastoreIdList -Property Name).Name

            ($dsNames | where{$script:dsEsx -notcontains $_}) -join '|'}}



  • 10.  RE: finding missing datastore _powercli

    Posted Jun 09, 2020 09:17 PM

    I tried something similar to that but with no luck. 

    Original script output:

    Name                          Cluster DS Count ESXi DS Count Missing DS

    ----                          ---------------- ------------- ----------

    HOSTD                9             6 HOSTB-Local|HOSTC-Local|HOSTA-Local

    HOSTB                9             6 HOSTD-Local|HOSTC-Local|HOSTA-Local

    HOSTC                9             5 HOSTD-Local|VVOL-DS|HOSTB-Local|HOSTA-Local

    HOSTA                9             6 HOSTD-Local|HOSTB-Local|HOSTC-Local

    Here is the new output from your suggestion:

    Name                          Cluster DS Count ESXi DS Count Missing DS

    ----                          ---------------- ------------- ----------

    HOSTD                5             6

    HOSTB                5             6

    HOSTA                5             6



  • 11.  RE: finding missing datastore _powercli

    Posted Jun 09, 2020 09:22 PM

    Isn't that what was requested?

    List all missing datastores, but exclude the local ones.



  • 12.  RE: finding missing datastore _powercli

    Posted Jun 09, 2020 10:10 PM

    I should see this if I can somehow filter out Local:

    HOSTC                9             5 VVOL-DS

    Sorry, I should have clarified.



  • 13.  RE: finding missing datastore _powercli

    Posted Jun 10, 2020 05:35 AM

    So that is a datastore only visible on that one ESXi node in the cluster.

    Does this datastore show and what does it show under the Multi property?

    Get-Cluster | Get-Datastore |

    Select Name,@{N='Multi';E={$_.ExtensionData.Summary.MultipleHostAccess}}



  • 14.  RE: finding missing datastore _powercli

    Posted Jun 10, 2020 12:39 PM

    Let me backup and start over.  Here is the original output from your script:  

    Name                          Cluster DS Count ESXi DS Count Missing DS

    ----                          ---------------- ------------- ----------

    HOSTD                9             6 HOSTB-Local|HOSTC-Local|HOSTA-Local

    HOSTB                9             6 HOSTD-Local|HOSTC-Local|HOSTA-Local

    HOSTC                9             5 HOSTD-Local|VVOL-DS|HOSTB-Local|HOSTA-Local

    HOSTA                9             6 HOSTD-Local|HOSTB-Local|HOSTC-Local

    It works great but I want to exclude all "Local" Datastores because when I run this against a Cluster with 20 hosts it will show 19 Local Datastores for each host. If you notice HOSTC, it has "VVOL-DS" missing ( I modified the font), this was on purpose.  I wanted to validate this script. 

    I basically want the output like this:

    Name                          Cluster DS Count ESXi DS Count Missing DS

    ----                          ---------------- ------------- ----------

    HOSTD                9             5

    HOSTB                9             5 

    HOSTC                9             5 VVOL-DS

    HOSTA                9             5

    Here is the output from your 1st suggestion:

    "$dsNames = (Get-Datastore -RelatedObject $cluster | where{$_.ExtensionData.Summary.MultipleHostAccess}).Name"

    Name                          Cluster DS Count ESXi DS Count Missing DS

    ----                          ---------------- ------------- ----------

    HOSTD                5             6

    HOSTB                5             6

    HOSTA                5             6

    Lastly, here is the output from your latest suggestion:

    PS /root> Get-Cluster IRC-00-MGMT | Get-Datastore |Select Name,@{N='Multi';E={$_.ExtensionData.Summary.MultipleHostAccess}}

    Name                           Multi

    ----                                -----

    TEMPLATES                True

    3PR1-01                       True

    3PR2-01                       True

    LOGI-NMB1-01            True

    HOSTC-Local              False

    VVOL-DS                    True

    HOSTB-Local              False

    HOSTB-Local              False

    HOSTA-Local              False

    To answer your last question, no, the datastore "VVOL-DS" is missing on HostC.

    Sorry for not being so thorough, Powershell is new for me.  I appreciate the help!