3 Replies Latest reply on Nov 8, 2019 2:29 AM by T180985

    Compare ProvisionedGB with CapacityGB

    T180985 Novice

      Hi All,

       

      I have the following script which pulls all the info i need for various datastores which works fine

       

      Get-Datastore | Select Datacenter, Name, Type, CapacityGB,

      @{N='ProvisionedGB';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)}},

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

      Sort Name | ft

       

      My problem is, i want to compare ProvisionedGB with CapacityGB and return a text value depending on whether its greater than or equal to.... Ive come up with the following which doesnt work so im hoping you can point me in the right direction

       

       

      Get-Datastore | Select Datacenter, Name, Type, CapacityGB,

      @{N='ProvisionedGB';E={[math]::round(($_ |get-vm | measure-Object ProvisionedSpaceGB -Sum).sum)}},

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

      @{N='OverProvisioned';E={If (ProvisionedGB -ge CapacityGB) {"OverProvisioned"} Else {"Capacity Available"} }}, state  |

      Sort Name | ft

       

      Frankly im not even sure that i can run an IF statement as an expression?

        • 1. Re: Compare ProvisionedGB with CapacityGB
          LucD Guru
          Community WarriorsvExpertUser Moderators

          Yes, you can, but you have to use the pipeline variable to access the properties.

          Like this

           

          Remove-OrphanedData -Datastore Get-Datastore | Select Datacenter, Name, Type, CapacityGB,

          @{N='ProvisionedGB';E={[math]::round(($_ |get-vm | measure-Object ProvisionedSpaceGB -Sum).sum)}},

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

          @{N='OverProvisioned';E={If ($_.ProvisionedGB -ge $_.CapacityGB) {"OverProvisioned"} Else {"Capacity Available"} }}, state  |

          Sort Name | ft

          • 2. Re: Compare ProvisionedGB with CapacityGB
            T180985 Novice

            I dont have Remove-OrphanedData as a function so i tried the following

             

            Get-Datastore | Select Datacenter, Name, Type, CapacityGB,

            @{N='ProvisionedGB';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)}},

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

            @{N='OverProvisioned';E={If ($_.ProvisionedGB -ge $_.CapacityGB) {"OverProvisioned"} Else {"Capacity Available"} }}, state  |

            Sort Name | ft

             

            This actually returns some text but all of them state "Capacity Available" even when over provisioned

            • 3. Re: Compare ProvisionedGB with CapacityGB
              T180985 Novice

              may not be pretty but it works...

               

              Get-Datacenter $global:DCChoice | Get-Cluster $global:CLUChoice |

              Get-Datastore | Select Datacenter, Name, Type, CapacityGB,

              @{N='ProvisionedGB';E={[math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)}},

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

              @{N='OverProvisioned';E={If ((($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB) -gt $_.CapacityGB) {"OverProvisioned"} Else {"Capacity Available"} }}, state  |

              Sort OverProvisioned | Where {$_.name -notlike "*-Local"} | ft