Creating a ticket in VMWare using PowerCLI when free storage in datastore is too less

59 views Asked by At

I am able to get the free space as ouptut by using the following code.

$body +=echo "------------Free space on Datastore.--------------"`r`n""`r`n""
$body +=get-datastore -name *datastore1* | sort Name | ForEach-Object {
    $output=New-Object -TypeName PSObject -Property @{
        Freespace = "$([math]::Round($_.FreeSpaceGB, 2)) GB"
        Datastore_Name = $_.Name
        }       
    }
    Write-Output $output

Is it possible to raise a ticket if the free space is less than 2 GB? If so, how should I change my code?

1

There are 1 answers

1
user3520245 On

EDIT :

if (get-datastore | where {$_.FreeSpaceGB -lt 2}){"dosomething"}

or

foreach ($ds in (get-datastore | where {$_.FreeSpaceGB -lt 2})){"dosomething"}