2,187
edits
(→ESXi Logs: Added some more bits) |
(→Script Extracts: Added "VM Storage Usage" and "ESX CDP Info") |
||
Line 367: | Line 367: | ||
</source> | </source> | ||
=== VM Storage Usage === | |||
'''Total''' storage usage (including any snapshots, logs, etc, etc), not just the VMDK files. | |||
Adapted from post by Arnim van Lieshout http://www.van-lieshout.com/2009/07/how-big-is-my-vm/ | |||
<source lang="powershell"> | |||
function Get-VMDiskUsage($vm2do) | |||
{ | |||
#Initialize variables | |||
$VMDirs =@() | |||
$VMSize = 0 | |||
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec | |||
$searchSpec.details = New-Object VMware.Vim.FileQueryFlags | |||
$searchSpec.details.fileSize = $TRUE | |||
Get-View -VIObject $vm2do | % { | |||
#Create an array with the vm's directories | |||
$VMDirs += $_.Config.Files.VmPathName.split("/")[0] | |||
$VMDirs += $_.Config.Files.SnapshotDirectory.split("/")[0] | |||
$VMDirs += $_.Config.Files.SuspendDirectory.split("/")[0] | |||
$VMDirs += $_.Config.Files.LogDirectory.split("/")[0] | |||
#Add directories of the vm's virtual disk files | |||
foreach ($disk in $_.Layout.Disk) { | |||
foreach ($diskfile in $disk.diskfile){ | |||
$VMDirs += $diskfile.split("/")[0] | |||
} | |||
} | |||
#Only take unique array items | |||
$VMDirs = $VMDirs | Sort | Get-Unique | |||
foreach ($dir in $VMDirs){ | |||
$ds = Get-Datastore ($dir.split("[")[1]).split("]")[0] | |||
$dsb = Get-View (($ds | get-view).Browser) | |||
$taskMoRef = $dsb.SearchDatastoreSubFolders_Task($dir,$searchSpec) | |||
$task = Get-View $taskMoRef | |||
while($task.Info.State -eq "running" -or $task.Info.State -eq "queued"){$task = Get-View $taskMoRef } | |||
foreach ($result in $task.Info.Result){ | |||
foreach ($file in $result.File){ | |||
$VMSize += $file.FileSize | |||
} | |||
} | |||
} | |||
} | |||
# VM disk usage in GB | |||
$VMSize/1048576000 | |||
} | |||
Get-VMDiskUsage (Get-VM "MyVM") | |||
</source> | |||
=== ESX CDP Info === | |||
Adapted from posted by LucD on VMware forum http://communities.vmware.com/message/977487 | |||
<source lang="powershell"> | |||
Get-VMHost | Sort -Property Name | %{Get-View $_.ID} | %{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | %{ | |||
foreach($physnic in $_.NetworkInfo.Pnic){ | |||
$pnicInfo = $_.QueryNetworkHint($physnic.Device) | |||
foreach($hint in $pnicInfo){ | |||
Write-Host $esxname $physnic.Device $hint.connectedSwitchPort.DevId $hint.connectedSwitchPort.PortId | |||
} | |||
} | |||
} | |||
</source> | |||
[[Category:VMware]] | [[Category:VMware]] | ||
[[Category:PowerShell]] | [[Category:PowerShell]] |