Hey guys -
I have a VDI environment we manage for a client and I've been using vCheck which I love. When running the snapshot and VM guest free space modules there's no built-in method for filtering out VM name. Since all of the VDI guests are "VDIxxxxxxx" I'd like to just exclude those guests from the module. Not great with powercli, is there a simple way? Here's the module in question:
$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){
if ((([math]::Round($disk.Capacity / 1MB)) -gt $MBDiskMinSize) -and (([math]::Round($disk.FreeSpace / 1MB)) -lt $MBFree)){
$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
Any help is appreciated!
Just add another clause to the where filter:
$AllVMs = $FullVM | Where {-not $_.Config.Template -and $_.Name -notmatch "^VDI" } | Where { $_.Runtime.PowerState -eq "poweredOn" -And ($_.Guest.toolsStatus -ne "toolsNotInstalled" -And $_.Guest.ToolsStatus -ne "toolsNotRunning")}
Is there a quick one or two lines I could add to filter OUT USB drives (or JUST report on drives like 'C')? I've been toying with this for about a week now and haven't found anything that seems to work....