Hello Everyone,
How to export the below 10% less free space C:\ drive server list using power CLI? I need to get with it .CSV format.
The format looks like the Server name, Drive, Capacity, and Free Space (less than 10%).
Please assist me. Thanks in advance.
What do you already have?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is what I found on the internet, I need the results in a format like the one below in CSV or Xslx format.
Format:
Server name, Drive (harddisk 1, 2,3), Free space, Percent free:
ForEach ($VM in Get-VM | where-object {($_.powerstate -ne "PoweredOff") -and ($_.Extensiondata.Guest.ToolsStatus -Match ".*Ok.*")}){
ForEach ($Drive in $VM.Extensiondata.Guest.Disk) {
$Path = $Drive.DiskPath
#Calculations
$Freespace = [math]::Round($Drive.FreeSpace / 1MB)
$Capacity = [math]::Round($Drive.Capacity/ 1MB)
$SpaceOverview = "$Freespace" + "/" + "$capacity"
$PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)
#VMs with less space
if ($PercentFree -lt 20) {
$Output = $Output + "Vm: " + $VM.Name + "`n"
$Output = $Output + "Disk: " + $Path + "`n"
$OutPut = $Output + "Free(MB): " + $Freespace + "`n"
$Output = $Output + "Free(%): " + $PercentFree + "`n"
}
$Output
Instead of accumulating the data in 1 variable ($output) use a Select-Object and calculated properties instead.
Then pipe the result to a CSV (Export-Csv)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I propose you do the update and I can verify if needed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference