Category Archives: VMWare

VMware Posts

List vSphere Datastores with less than 20% Free Space

The below script lists all datastores with less than 20% free space:


Connect-VIServer -Server vCenterName

function CalcPercent {
param(
[parameter(Mandatory = $true)]
[int]$InputNum1,
[parameter(Mandatory = $true)]
[int]$InputNum2)
$InputNum1 / $InputNum2*100
}

$datastores = Get-Datastore | Sort Name
ForEach ($ds in $datastores)
{
if (($ds.Name -match "Shared") -or ($ds.Name -match ""))
{
$PercentFree = CalcPercent $ds.FreeSpaceMB $ds.CapacityMB
$PercentFree = "{0:N2}" -f $PercentFree
$ds | Add-Member -type NoteProperty -name PercentFree -value $PercentFree
}
}
$datastores | where-object {$_.PercentFree -le 20} | Select Name,FreeSpaceGB,CapacityGB,PercentFree
Facebooktwittergoogle_pluslinkedinby feather

PowerCLI Get ESXi Host and Version

This script will connect to a vCenter server and list all hosts it can see and the version of ESXi running on the host. I have also exported this to a csv

Add-PSSnapinVMware.VimAutomation.Core

Connect-VIServer-Server vSphereServerName

Get-VMHost | Select Name,Version,@{N="vCenter";E={$_.ExtensionData.CLient.ServiceUrl.Split('/')[2]}} |ft name,version | Out-File FileLocation

Facebooktwittergoogle_pluslinkedinby feather