Skip to content

Posts from the ‘VMWare’ Category

30
Jan

Get Guest VM Drive Sizes

Quick post on how to get the drive sizes and free space on said drives on VMWare Virtual Machines.  Props to this forum post.  I ran this on our esx’s and was able to identify over 2 terabytes of unused space.  Very handy.

cls

$user = 'UserName'
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $user, (get-content "c:\credentialFile.txt" | convertto-securestring )
#Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue
$visrv = Connect-VIServer -Server Server -Credential $cred

$dataCenter = Get-Datacenter -Name Location 

if(Test-Path('c:\ServerList.csv'))
{
	Remove-Item -Path c:\ServerList.csv -force
}

Get-VM -Location $dataCenter | %{ $vmName = $_.Name;
	$_.Guest.Disks | where{($_.FreeSpace/1GB) -gt 50} | Select `
			@{Name = "VirtualMachine"; E={$vmName}}, `
			@{Name = "Path"; E={$_.Path}}, `
			@{Name = "Capacity(GB)";E={[System.Math]::Round($_.Capacity/1GB, 1)}}, `
			@{Name = "FreeSpace(GB)";E={[System.Math]::Round($_.FreeSpace/1GB, 1)}}  
} | Export-Csv -Path 'c:\ServerList.csv'

Disconnect-VIServer -Server $visrv -Force
30
Jan

Last Login Date for VM

Quick query to show VMs that have not been logged into within the last 3 months.  Adapted from this forum post.

SELECT 
	VM_Name,
	UserName,
	[Host_Name],
	DataCenter_Name,
	MAX(Create_Time)
	FROM dbo.vpx_event
WHERE EVENT_TYPE = 'vim.event.VmAcquiredMksTicketEvent'
AND DATEDIFF(MONTH, Create_Time, GETDATE()) >= 3
GROUP BY 
	VM_Name,
	UserName,
	[Host_Name],
	DataCenter_Name