VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

Need help placing the Where-Object filter in the correct place

HI,

I'm trying to filter out the local datastores but I'm not getting the desired results.

Code:

Get-Datastore | Select @{N="LUN";E={$_.Name}},

                       @{N="Total VMs";E={@($_ | Get-VM).Count}} |

                       Where-Object {$_Name -Notlike "Datastore1*"}

Thanks

0 Kudos
1 Solution

Accepted Solutions
TScalzott
Enthusiast
Enthusiast
Jump to solution

As a general rule, you want to filter first where possible for increased efficiency down the pipeline.  That's no exception here:

Try:

Get-Datastore | Where-Object {$_Name -Notlike "Datastore1*"} |

    Select @{N="LUN";E={$_.Name}}, @{N="Total VMs";E={@($_ | Get-VM).Count}}

View solution in original post

0 Kudos
2 Replies
TScalzott
Enthusiast
Enthusiast
Jump to solution

As a general rule, you want to filter first where possible for increased efficiency down the pipeline.  That's no exception here:

Try:

Get-Datastore | Where-Object {$_Name -Notlike "Datastore1*"} |

    Select @{N="LUN";E={$_.Name}}, @{N="Total VMs";E={@($_ | Get-VM).Count}}

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

This worked thanks!

Get-Datastore | Where-Object {$_.Name -Notlike "Datastore*"} |

    Select @{N="LUN";E={$_.Name}},

           @{N="Total VMs";E={@($_ | Get-VM).Count}}

and thanks for the tip!

0 Kudos