Hi,
I would like to know the free space of VM, I am able to get the Provisioned Space and Used Space but I am not sure, how to get free space.
Please help
Get-VM | Get-HardDisk |
Select @{N='VM Name';E={$_.Parent.Name}},
@{N="IP Address";E={@($_.Parent.guest.IPAddress[0])}},
@{N="VM PowerState";E={@($_.Parent.PowerState)}},
@{N='VM Provisioned Space';E={$_.Parent.ProvisionedSpaceGB}},
@{N='VM Free Space';E={$_.Parent.FreeSpaceGB}},
There is no such property as "FreeSpaceGB" for a virtual machine
vSphere 6.0 Documentation Center
(The "$_.Parent" in your script is a virtual machine)
Hi,
I modified a Plugin from vCheck to get work done:
$FullVM = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template}
$MyCollection = @()
$AllVMs = $FullVM | Where {-not $_.Config.Template } | Where { $_.Runtime.PowerState -eq "poweredOn" -And ($_.Guest.toolsStatus -ne "toolsNotInstalled" -And $_.Guest.ToolsStatus -ne "toolsNotRunning")}
$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VMdsk in $SortedVMs){
$Details = New-object PSObject
$DiskNum = 0
$Details | Add-Member -Name Name -Value $VMdsk.name -Membertype NoteProperty
Foreach ($disk in $VMdsk.Guest.Disk){
$Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))
$Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
$DiskNum++
}
if ($DiskNum -gt 0){
$MyCollection += $Details
}
}
$MyCollection
Hi Markus,
How do I run the above script, just save as ps1 and execute ?
Where can I specify the just one VM name to test against one VM?
Hi,
you need VMware PowerCLI installed on your Management System.
then load the VMware PlugIn:
# Load SnapIn
if (!(get-pssnapin -name VMware.VimAutomation.Core -erroraction silentlycontinue)) {
add-pssnapin VMware.VimAutomation.Core
}
Connect Your vCenter:
# Connect to vCenter
Connect-VIServer <your vCenter FQDN>
the you can past the prior script or Save it as ps1 and execute it.
If you only need specific VMs modify this line to filter:
$FullVM = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template}
Thanks for your reply.
How do I get the free disk percentage added to the script ?
This should work:
$MyCollection = @()
$AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template } | Where { $_.Runtime.PowerState -eq "poweredOn" -And ($_.Guest.toolsStatus -ne "toolsNotInstalled" -And $_.Guest.ToolsStatus -ne "toolsNotRunning")}
$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VMdsk in $SortedVMs){
$Details = New-object PSObject
$DiskNum = 0
$Details | Add-Member -Name Name -Value $VMdsk.name -Membertype NoteProperty
Foreach ($disk in $VMdsk.Guest.Disk){
$Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity / 1MB))
$Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
$Details | Add-Member -Name "Disk$($DiskNum)PercentFree(%)" -Membertype NoteProperty -Value ([math]::Round(100 * $disk.FreeSpace / $disk.Capacity))
$DiskNum++
}
if ($DiskNum -gt 0){
$MyCollection += $Details
}
}
$MyCollection
It workls, You are simply superb
One last thing, anyway to get VM Folder details
how to get folder details of VM in above script
How would I go about saving the result of this script to a file on my system? Something that I could pull into Excel would be a good baseline. Also, if I wanted to just get this info on a few VMs in the environment, what would that look like?
I'm really new to using PowerCLI/PowerShell so bear with me...
Found the answer for how to send it to a file on my system... Just used the "out-file" command along with "-noclobber" in my first pass. I can get both .txt and .csv files this way. Just no formatting inside the file (so can't make the csv file with columns and such. At least I can get a file from this... I'll look into having the file name with a date stamp suffix next...
ganapa2000 schrieb:
how to get folder details of VM in above script
$MyCollection = @()
$AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template } | Where { $_.Runtime.PowerState -eq "poweredOn" -And ($_.Guest.toolsStatus -ne "toolsNotInstalled" -And $_.Guest.ToolsStatus -ne "toolsNotRunning")}
$SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
ForEach ($VMdsk in $SortedVMs){
$Details = New-object PSObject
$DiskNum = 0
$Details | Add-Member -Name Name -Value $VMdsk.name -Membertype NoteProperty
$Details | Add-Member -Name Folder -Value (Get-View $VMdsk.Parent | Select -ExpandProperty Name) -Membertype NoteProperty
Foreach ($disk in $VMdsk.Guest.Disk){
$Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath
$Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity / 1MB))
$Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
$Details | Add-Member -Name "Disk$($DiskNum)PercentFree(%)" -Membertype NoteProperty -Value ([math]::Round(100 * $disk.FreeSpace / $disk.Capacity))
$DiskNum++
}
if ($DiskNum -gt 0){
$MyCollection += $Details
}
}
$MyCollection
My Source for the extension: Re: Folder a VM is in using Get-View
Thanks to LucD
Hi,
to export the data for further processing I prefer CSV:
$MyCollection | Export-Csv -Path C:\temp\DiskReport.csv
Just modify the last line.