1 2 Previous Next 26 Replies Latest reply on May 27, 2019 5:40 AM by jvm2016

    whats_wrong_infollowingcode_powercli

    jvm2016 Expert

      HI Luc,

      please suggest what is wrong in following.

      this is to find max freespace percentage datastore fro a given vm .

       

      $entity=read-host "provide entity"

       

      if((Get-VM -ErrorAction SilentlyContinue).Name -contains $entity){

          Write-Host "It's a VM" -ForegroundColor Yellow

          $vm = Get-VM -Name $entity

          $ds = Get-Datastore -RelatedObject $vm

          if($ds.count -gt 1)

          {

          write-host "vm is configured for "$ds.count "datastores"

       

          $datastores_freepercent=$ds|ForEach-Object -Process {

       

                                                      $per_freespace=$_.freespaceGB/$_.capacityGB*100

        

       

                                                        $per_freespace_round=[math]::Round($per_freespace)

        

       

         

         

                                                      $datastores=$ds|select name,@{N='freespacepercent';E={$per_freespace_round}}

                                                      $datastores

        

      }}}

        1 2 Previous Next