VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot

Property type calling in object

Hello All,



If i use a property on get-vm I get the results such as get-vm.harddisks

Storagetype:
name:
filename:

etc.

Now i am trying to take the  stroagetype and check if its Type = thin then list.

so what I am doing is creating a custom psobject and adding the $_.storagetype in there.

Now how do i do if($object.storagetype -eq "Thin"){ xxx}

Please advice

Thanks

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
3 Replies
LucD
Leadership
Leadership

This can be done in a similar way as the other thread you started, with a Where-clause.

foreach($vm in Get-VM){
    foreach($hd in ($vm.Harddisks | where {$_.StorageFormat -eq "Thin"})){
        New-Object PSObject -Property @{
            VM = $vm.Name
            HD = $hd.Name
            Type = $hd.StorageType
        }
    }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranjitcool
Hot Shot
Hot Shot

Thanks Luc,

So here we are creating three members in the new object - which is $New-Object? or what is the object name?

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
0 Kudos
LucD
Leadership
Leadership

The cmdlet is New-Object and we use a builtin, empty object, which is called PSObject.

The New-Object cmdlet places the new object on the pipeline.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos