VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

How to add Cluster Name to Report

Get-DataCenter $DC | Get-Datastore | Where-Object {$_.Name -notlike "DataStore1*"} |

Sort-Object -Property Name |

Select-Object -Property Name,

@{Name="CapacityGB";Expression={[Math]::Round($_.CapacityGB,0)}},

@{Name="UsedSpaceGB";Expression={[Math]::Round($_.CapacityGB-$_.FreeSpaceGB,0)}},

@{Name="FreeSpaceGB";Expression={[Math]::Round($_.FreeSpaceGB,0)}},

@{Name="UncommittedSpaceGB";Expression={

  if (-not $_.ExtensionData.Summary.Uncommitted) {

    0

  }

  else {

    [Math]::Round($_.ExtensionData.Summary.Uncommitted/1GB,0)

  }

}},

@{Name="ProvisionedSpaceGB";Expression={

    $Summary = $_.ExtensionData.Summary

    if (-not $Summary.Uncommitted) {

      [Math]::Round(($Summary.Capacity - $Summary.FreeSpace)/1GB,0)

    }

    else {

      [Math]::Round(($Summary.Capacity - $Summary.FreeSpace + $Summary.Uncommitted)/1GB,0)

    }

}},

@{Name="PercentageUsed";Expression={[Math]::Round(100*($_.CapacityGB-$_.FreeSpaceGB)/$_.CapacityGB,0)}},

@{Name="PercentageFreeSpace";Expression={[Math]::Round(100*$_.FreeSpaceGB/$_.CapacityGB,0)}},

@{Name="PercentageProvisioned";Expression={

    $Summary = $_.ExtensionData.Summary

    if (-not $Summary.Uncommitted) {

      [Math]::Round(100*($Summary.Capacity - $Summary.FreeSpace)/$Summary.Capacity,0)

    }

    else {

      [Math]::Round(100*($Summary.Capacity - $Summary.FreeSpace + $Summary.Uncommitted)/$Summary.Capacity,0)

    }

}},

@{Name="VMs";Expression={[string]::Join(";",($_.ExtensionData.Vm | ForEach-Object {Get-View -Id $_}).Name)}},

@{Name="VMDKs";Expression={[string]::Join(";",(&{

    $Datastore = $_

    $Datastore.ExtensionData.Vm |

    ForEach-Object {

      Get-View -Id $_ |

      Get-VIObjectByVIView |

      Get-HardDisk |

      Where-Object {$_.FileName -like "*$($Datastore.Name)*"}

    }

  }).FileName)

 

 

}} | Export-CSV $FileName -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try adding this calculated property

@{N="Cluster";E={Get-VMHost -Datastore $_ | Get-Random | Get-Cluster | Select -ExpandProperty Name}},


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try adding this calculated property

@{N="Cluster";E={Get-VMHost -Datastore $_ | Get-Random | Get-Cluster | Select -ExpandProperty Name}},


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

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

Thanks Luc!

0 Kudos