Automation

 View Only
  • 1.  Help getting cluster name for array / datastore

    Posted Jul 13, 2018 04:53 PM

    I borrowed this script from another thread, it was created by LucD.  I cannot get the following line to show me the cluster name for the datastore, I know I am missing something, I just don't know what.  The report shows every other row, but for cluster it is just blank.  The script is pulling all datastores that are less than 20% free space and converting that data to an HTML file for reporting purpose.

    @{N='Cluster';E={$_.Cluster.Name}},

    &{foreach($vc in $global:DefaultVIServers){

        Get-Datastore | ? {($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and ($_.Name -notlike "*LOG*)} |

        where {($_.FreeSpaceGB/$_.CapacityGB) -le 0.20} |

        Select @{N='vCenter';E={$vc.Name}},

            @{N='Cluster';E={$_.cl.Name}},

            @{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

            @{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}},

         

    }

    ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html

    Appreciate the help!



  • 2.  RE: Help getting cluster name for array / datastore

    Posted Jul 13, 2018 05:10 PM

    Did you mean something like this?

    &{foreach($vc in $global:DefaultVIServers){

        Get-Cluster -Server $vc -PipelineVariable cluster |

        Get-Datastore -Server $vc |

        where{($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and

              ($_.Name -notlike "*LOG*") -and

              (($_.FreeSpaceGB/$_.CapacityGB) -le 0.20)} |

        Select @{N='vCenter';E={$vc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            @{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

            @{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}

    }} |

    ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html



  • 3.  RE: Help getting cluster name for array / datastore

    Posted Jul 13, 2018 05:39 PM


    Thank you for the reply.  I attempted that and I get this error message repeating for each cluster:

    Get-Datastore | The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

    At pathtoscript.ps1:3 char:2

    Get-Datastore -Server $vc |

    When I comment out:

    Get-Cluster -Server $vc -PipelineVariable cluster |,

    The script runs but it does not display the cluster name in the output, vCenter, Freespace% and FreespaceGB show up without issue and it only displays datastores with less than 20%, so that part is good.



  • 4.  RE: Help getting cluster name for array / datastore

    Posted Jul 13, 2018 06:24 PM

    You seem to be on an older version of PowerCLI.

    Can you check with Get-PowerCLIVersion?



  • 5.  RE: Help getting cluster name for array / datastore

    Posted Jul 13, 2018 06:58 PM

    You are correct, the version was causing this.  One last question, is there anyway to sort the output by the % free, the lowest free space at the top?

    I appreciate all the help getting me this far!



  • 6.  RE: Help getting cluster name for array / datastore
    Best Answer

    Posted Jul 13, 2018 07:19 PM

    Try like this

    &{foreach($vc in $global:DefaultVIServers){

        Get-Cluster -Server $vc -PipelineVariable cluster |

        Get-Datastore -Server $vc |

        where{($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and

              ($_.Name -notlike "*LOG*") -and

              (($_.FreeSpaceGB/$_.CapacityGB) -le 0.20)} |

        Select @{N='vCenter';E={$vc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            @{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

            @{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}

    }} |

    Sort-Object -Property 'Freespace%' -Descending |

    ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html



  • 7.  RE: Help getting cluster name for array / datastore

    Posted Jul 13, 2018 07:36 PM

    Thank you!