In my previous blog I (re)created of extend a existing PowerCLI function that showed an overview of the user vGPU resources. If not you can read it here:

Like I mentioned in the previous blog. My goal was to create a script based of my used profiles and find the remaining capacity of my GPU cluster(s). And of course you need that function ;-). Don’t forget to connect to you vCenter. After loading the Get-vGPUOverview function we start using the script.

There is one last thin before using the script and function. I am dot sourcing the Get-vGPUOverview and filter out the result, why I do that? You can re-use variables that are created in that particular function. And in this case I need the $output variable.

When you run a script that is dot sourced, the commands in the script run as though you had typed them at the command prompt. The functions, variables, aliases, and drives that the script creates are created in the scope in which you are working. After the script runs, you can use the created items and access their values in your session.

. Get-vGPUOverview -Cluster 'Your_gpu_cluster' | Out-Null

#The vGPU profiles I use
$GPUProfiles = 'grid_t4-1q','grid_t4-2q','grid_t4-4q'
#Total GB per GPU
$GBPerGPU = '16'
#number of GPU cards without any VDI/VM
$FreeGPUs = $output | select 'VDIname' | ? {$_ -match 'NoVDIs'}

#A $variable.count not available with only one item in it.
$nmbrFreeGPUs = $FreeGPUs.Count
    $nmbrFreeGPUs = 1

foreach($GPUProfile in $GPUProfiles){
    #Get all VDI per vGPU profile type
    $All = $output | select HostName,ProfileType,CardId | ? {$_ -match $GPUProfile}
    $nmbrVDI = $All.count

    #Get number of cards used by this profile
    $UsedCards = $All | sort -Unique 'Hostname','CardId'
    $nmbrUsedCards = $UsedCards.count

    #A $variable.count not available with only one item in it.
        $nmbrVDI = 1
        $nmbrUsedCards = 1

    #Get GB value from a GPU profile
    $split = $GPUProfile.Split('-')
    $pattern = "(?<=.*$($split[0])).*(?=[a-z].*)"
    $GB = [Regex]::Match($GPUProfile, $pattern).Value.replace('-','')
    $totalMem = $nmbrVDI * $GB

    #Calculating available VDI on the used GPU
    "Available $GPUProfile : $(($nmbrUsedCards * $GBPerGPU - $totalMem) / $GB) VDI"

"The number of GPU cards not yet used: $($nmbrFreeGPUs)"

 2,626 total views,  6 views today