1 2 Previous Next 19 Replies Latest reply on Feb 24, 2020 2:31 AM by LucD Go to original post
      • 15. Re: How to get Free space disk vm in Cluster
        LucD Guru
        Community WarriorsUser ModeratorsvExpert

        There could be two reasons why a VM is not in the list.

        - the VM doesn't have VMware Tools installed or has been powered for a longer time. Then the Disks property might be empty

        - the VM doesn't have drives that start with C or D

        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
        • 16. Re: How to get Free space disk vm in Cluster
          vespavbb Novice

          Hi,

           

          how can I pipe the PipelineVariable VM with a filter like where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*'}

           

          and is the a why for check each driveletter whats inside the VM, or is the only why like $_.Path -match "^C|^D|^E|^F|^G|^H|^I|^J|^K .....and so on"

           

           

           

          Thanks...

           

          ps for linux works diffent or even is not possible?

          • 17. Re: How to get Free space disk vm in Cluster
            LucD Guru
            Community WarriorsvExpertUser Moderators

            You don't need to use the pipelinevariable for that, you can just insert the Where-clause in the pipeline.

             

            $clusterName = 'cluster'

            Get-Cluster -Name $clusterName |

            Get-VM -PipelineVariable vm |

            where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*'} |

            ForEach-Object -Process {

              Get-VMGuest -VM $vm |

              Select-Object -ExpandProperty Disks |

              Sort-Object -Property Path |

              Where-Object{$_.Path -match "^C|^D"} |

              Select-Object @{N='VM';E={$vm.Name}},

                Path,

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

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

            } |

            Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


            Not sure what you mean by "... check each driveletter whats inside the VM ...".
            Since the script expands the Disks property, all known disks will be listed.

             

            For Linux the Path will be off the format /folder.
            You can filter on that as well, for example

             

            Where-Object{$_.Path -match "^/bin"}

            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            • 18. Re: How to get Free space disk vm in Cluster
              vespavbb Novice

              ah ok thanks,

               

              one more question. I want to ad a Line for something like Warning if free space is under 10% and modify the output to get anly VM´s with freespace under 10%

              the output for Warning is allways TRUE ?

               

              ForEach-Object -Process {

               

                Get-VMGuest -VM $vm |

                Select-Object -ExpandProperty Disks |

               

                Sort-Object -Property Path |

               

                Where-Object{$_.Path -match "^C|^D|^E|^F|^G|^H|^I|^J|^K|^L|^M|^N" } |

               

                Select-Object @{N='VM';E={$vm.Name}},

               

                  Path,

               

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

               

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

               

                  @{N='Warning';E={[math]::($_.FreeSpaceGB/$_.CapacityGB) -le 0.10}}

                

               

              }

               

              • 19. Re: How to get Free space disk vm in Cluster
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                That is because of the Round you are using.

                Any value less or equal to 0.5 will be rounded to 0, hence the $true for all those.

                Just use

                 

                @{N='Warning';E={$_.FreeSpaceGB/$_.CapacityGB -le 0.10}}
                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                1 2 Previous Next