VMware Cloud Community
Troy_Clavell
Immortal
Immortal
Jump to solution

More Free Space Reporting...

We have requirements to report on a group of VMs in certain blue folders.  We would like to generate a report for VMs with less the 100MB of free space.

Taking the script developed in Report Free Space, is this something that can be done?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this

$blueFolders = "Blue1","Blue2" 
$expression1 = [string]::Join('|',$blueFolders)

$folderMoRef = Get-View -ViewType Folder -Property Name -Filter @{"Name"=$expression1} | %{
   $_.MoRef.Value
}
$expression2 = [string]::Join('|',$folderMoRef ) &{foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Guest.Disk `
  -Filter @{"Runtime.PowerState"="poweredOn";"Parent"=$expression2}){    $vm.Guest.Disk | where {$_.FreeSpace -le 100MB} |
 
Select @{N="VMname";E={$vm.Name}},
   
@{N="Path";E={$_.DiskPath}},
    @{N="MBFree";E={[math]::Round(($_.FreeSpace/1MB),0)}},
    @{ N="PercFree"; E={[math]::Round((100*($_.FreeSpace/$_.Capacity)),0)}} }} | Sort PercFree | Export-Csv C:\freespace.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

Does the addition of this Where-clause produce the results you're after ?

$blueFolders = "Blue1","Blue2" 
$expression1 = [string]::Join('|',$blueFolders)

$folderMoRef = Get-View -ViewType Folder -Property Name -Filter @{"Name"=$expression1} | %{
   $_.MoRef.Value
} $expression2 = [string]::Join('|',$folderMoRef ) &{foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Guest.Disk `
  -Filter @{"Runtime.PowerState"="poweredOn";"Parent"=$expression2}){    $vm.Guest.Disk | where {$_.FreeSpace -le 100MB} |
  Select @{N="VMname";E={$vm.Name}},
   
@{N="Path";E={$_.DiskPath}},
   
@{ N="PercFree"; E={[math]::Round((100*($_.FreeSpace/$_.Capacity)),0)}} }} | Sort PercFree | Export-Csv C:\freespace.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Troy_Clavell
Immortal
Immortal
Jump to solution

very very close!!   Is there a way to add into the csv file a field called MBFree and show how much MB is actually free along with the PercFree

here are the results of the output now

VMnamePathPercFree
PHX1V2240070C:\0
PHX1V2240101C:\0
PHX1V2240099C:\0

an example of what would be ideal:

VMnamePathPercFreeMBFree
PHX1V2240070C:\030
PHX1V2240101C:\010
PHX1V2240099C:\095
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this

$blueFolders = "Blue1","Blue2" 
$expression1 = [string]::Join('|',$blueFolders)

$folderMoRef = Get-View -ViewType Folder -Property Name -Filter @{"Name"=$expression1} | %{
   $_.MoRef.Value
}
$expression2 = [string]::Join('|',$folderMoRef ) &{foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Guest.Disk `
  -Filter @{"Runtime.PowerState"="poweredOn";"Parent"=$expression2}){    $vm.Guest.Disk | where {$_.FreeSpace -le 100MB} |
 
Select @{N="VMname";E={$vm.Name}},
   
@{N="Path";E={$_.DiskPath}},
    @{N="MBFree";E={[math]::Round(($_.FreeSpace/1MB),0)}},
    @{ N="PercFree"; E={[math]::Round((100*($_.FreeSpace/$_.Capacity)),0)}} }} | Sort PercFree | Export-Csv C:\freespace.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

my friend, as always, thank you is never enough.

Ths is perfect!!!

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

Hello again Smiley Happy

Another slight modification:

Within  the report, can we have the "blue folder" in the csv output? Since the  folders match the pool names in View, can it look something like?

VmnamePathMBFreePercFreePool
PHX1V2240101C:\30Pool 1
PHX1V2240070C:\10Pool 2
PHX1V2240099C:\110Pool 3
PHX1V2930701C:\50Pool 4
PHX1V2930707C:\200Pool 5
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try this

$blueFolders = "Blue1","Blue2" 
$expression1 = [string]::Join('|',$blueFolders)

$folderMoRef = Get-View -ViewType Folder -Property Name -Filter @{"Name"=$expression1} | %{
   $_.MoRef.Value
} $expression2 = [string]::Join('|',$folderMoRef ) &{foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Parent,Guest.Disk `
  -Filter @{"Runtime.PowerState"="poweredOn";"Parent"=$expression2}){    $vm.Guest.Disk | where {$_.FreeSpace -le 100MB} |
  Select @{N="VMname";E={$vm.Name}},
    @{N="Path";E={$_.DiskPath}},
    @{N="MBFree";E={[math]::Round(($_.FreeSpace/1MB),0)}},
   
@{N="PercFree"; E={[math]::Round((100*($_.FreeSpace/$_.Capacity)),0)}},
   
@{N="Pool";E={Get-View $vm.Parent | Select -ExpandProperty Name}} }} | Sort PercFree | Export-Csv C:\freespace.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Troy_Clavell
Immortal
Immortal
Jump to solution

You are a machine!!

Thank you, again!!!!

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

bumping and old thread due to new requirements

We only need to report on C: drive space, not all drives.  Easy edit?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Expand the Where-clause.

Something like this

where {$_.DiskPath -match "^C:\\" -and $_.FreeSpace -le 100MB}



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

didn't really work too well. I filtered for anything less the 500MB to get some results.    the results should look like my reply above,

Re: More Free Space Reporting...


However they appear different now


DiskPathCapacityFreeSpaceDynamicTypeDynamicProperty
C:\12888977408513196032
C:\12888977408344416256
C:\12888977408491610112
C:\12888977408451809280
C:\12888977408475729920

Here is the script:

$blueFolders = "BannerAZCoders", "HCSCoders", "BannerWRCoders", "BannerWRFltCoder", "BannerAZFltCdr", "HIMsOpsStaff", "HIMSCROI", "HIMSPericalm", "HIMSRAC", "HIMSRAC2"

$expression1 = [string]::Join('|',$blueFolders)

$folderMoRef = Get-View -ViewType Folder -Property Name -Filter @{"Name"=$expression1} | %{

   $_.MoRef.Value

}

$expression2 = [string]::Join('|',$folderMoRef )

&{foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Parent,Guest.Disk `

  -Filter @{"Runtime.PowerState"="poweredOn";"Parent"=$expression2}){ 

# $vm.Guest.Disk | where {$_.FreeSpace -le 200MB} |

$vm.Guest.Disk |where {$_.DiskPath -match "^C:\\" -and $_.FreeSpace -le 500MB}

  Select @{N="VMname";E={$vm.Name}},

    @{N="Path";E={$_.DiskPath}},

    @{N="MBFree";E={[math]::Round(($_.FreeSpace/1MB),0)}},

    @{N="PercFree"; E={[math]::Round((100*($_.FreeSpace/$_.Capacity)),0)}},

    @{N="Pool";E={Get-View $vm.Parent | Select -ExpandProperty Name}}

}} | Sort PercFree |

Export-Csv C:\scripts\vpcspace.csv -NoTypeInformation

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think you forgot the pipeline symbol (|) at the end of the line with the Where-clause


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

that was it!!!

a pint of your favorite beverage, on me, at VMworld

Thanks, Luc!

0 Kudos