I have a report that shows all datastores in a DC and shows what percent is running on that datastore so I can check the load and keep it balanced manually if needed, but I added a cold storage datastore and it's showing up in this report, what is the best way to remove it:
##################
# Variables #
###################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="\var\www\NAS-Loads\VDC-NAS-Load\VDC-NAS-Load-$date.htm"
#############################
# Add Text to the HTML file #
#############################
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$dcName = 'VDC'
$ds = Get-Datacenter -Name $dcName | Get-Datastore |
where {$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess}
$totalSpaceUsed = $ds | % {$_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum | select -ExpandProperty Sum
Get-Stat -Entity $ds -Stat 'disk.used.latest' -Realtime -MaxSamples 1 -Instance '' |
ForEach-Object -Process {
New-Object PSObject -Property @{
Datastore = $_.Entity.Name
PercentofTotalSpaceGB = [math]::Round(($_.Value / 1MB) / $totalSpaceUsed * 100, 1)
}
} |
Sort-Object -Property Datastore |
Select Datastore, PercentofTotalSpaceGB |
ConvertTo-Html -Head $Header |
Out-File $filelocation
Invoke-Item -Path .\report.html
Assuming that Tag name is 'ColdData', you could do
where {$_.Type -eq 'VMFS' -and
$_.ExtensionData.Summary.MultipleHostAccess -and
(Get-TagAssignment -Entity $_).Tag.Name -ne 'ColdData'}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there a way to identify that datastore? By name, tag, folder, location ...?
If yes, you could extend the Where clause in
where {$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes the datastores have a tag of on them, how do I extend the where for that?
Assuming that Tag name is 'ColdData', you could do
where {$_.Type -eq 'VMFS' -and
$_.ExtensionData.Summary.MultipleHostAccess -and
(Get-TagAssignment -Entity $_).Tag.Name -ne 'ColdData'}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Very sorry seems it is working to eliminate the extra datastores, but now is it showing the Percentage as this ∞
When I run the script manually I do see an error: Cannot find path '/root/report.html' because it does not exist.
I assume this is referring to the last line of the script: Invoke-Item -Path .\report.html
but I don't understand that line to begin with 😕
Are you running this on a non-Windows OS?
Did you make sure that the environment is configured to use UTF-8 (without BOM)?
Which PS version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am running it on centos 8 with the newest PS that I know of:
PowerCLI Version
----------------
VMware PowerCLI 12.0.0 build 15947286
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.0 build 15939652
VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655
I checked and this worked until I updated the script with the tag exclusions tho.
Can you use the Linux path separator ('/') instead of the Windows one ('\')?
I assume that you run this on a CentOS with a Desktop which has a registered app for opening HTML files?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oh very sorry I just commented out one too many lines from the bad code. Thank you again, you are a life saver.