I borrowed this script from another thread, it was created by LucD. I cannot get the following line to show me the cluster name for the datastore, I know I am missing something, I just don't know what. The report shows every other row, but for cluster it is just blank. The script is pulling all datastores that are less than 20% free space and converting that data to an HTML file for reporting purpose.
@{N='Cluster';E={$_.Cluster.Name}},
&{foreach($vc in $global:DefaultVIServers){
Get-Datastore | ? {($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and ($_.Name -notlike "*LOG*)} |
where {($_.FreeSpaceGB/$_.CapacityGB) -le 0.20} |
Select @{N='vCenter';E={$vc.Name}},
@{N='Cluster';E={$_.cl.Name}},
@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}},
}
ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html
Appreciate the help!
Try like this
&{foreach($vc in $global:DefaultVIServers){
Get-Cluster -Server $vc -PipelineVariable cluster |
Get-Datastore -Server $vc |
where{($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and
($_.Name -notlike "*LOG*") -and
(($_.FreeSpaceGB/$_.CapacityGB) -le 0.20)} |
Select @{N='vCenter';E={$vc.Name}},
@{N='Cluster';E={$cluster.Name}},
@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}
}} |
Sort-Object -Property 'Freespace%' -Descending |
ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you mean something like this?
&{foreach($vc in $global:DefaultVIServers){
Get-Cluster -Server $vc -PipelineVariable cluster |
Get-Datastore -Server $vc |
where{($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and
($_.Name -notlike "*LOG*") -and
(($_.FreeSpaceGB/$_.CapacityGB) -le 0.20)} |
Select @{N='vCenter';E={$vc.Name}},
@{N='Cluster';E={$cluster.Name}},
@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}
}} |
ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the reply. I attempted that and I get this error message repeating for each cluster:
Get-Datastore | The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At pathtoscript.ps1:3 char:2
Get-Datastore -Server $vc |
When I comment out:
Get-Cluster -Server $vc -PipelineVariable cluster |,
The script runs but it does not display the cluster name in the output, vCenter, Freespace% and FreespaceGB show up without issue and it only displays datastores with less than 20%, so that part is good.
You seem to be on an older version of PowerCLI.
Can you check with Get-PowerCLIVersion?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are correct, the version was causing this. One last question, is there anyway to sort the output by the % free, the lowest free space at the top?
I appreciate all the help getting me this far!
Try like this
&{foreach($vc in $global:DefaultVIServers){
Get-Cluster -Server $vc -PipelineVariable cluster |
Get-Datastore -Server $vc |
where{($_.name -like "LUN*" -or $_.Name -like "iSCSI*") -and
($_.Name -notlike "*LOG*") -and
(($_.FreeSpaceGB/$_.CapacityGB) -le 0.20)} |
Select @{N='vCenter';E={$vc.Name}},
@{N='Cluster';E={$cluster.Name}},
@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}}
}} |
Sort-Object -Property 'Freespace%' -Descending |
ConvertTo-HTML -CssUri "pathtomycssfile" | Out-File c:\temp\datastore_report.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you!