VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Exclude certain datastores

Hi,

Below script excludes one particular datastore from the output, but how can I exclude multiple datastores from the below script,

please help

Get-Cluster MyClus | Get-Datastore | Sort-Object -Property {$_.FreeSpaceGB} -Descending:$true | where {$_.Name -ne "datastore1"} | Select-Object -ExpandProperty Name -First 1

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use the -notcontains operator.

$excludeNames = 'datastore1','datastore2','datastore3'

Get-Cluster MyClus |

Get-Datastore |

Sort-Object -Property {$_.FreeSpaceGB} -Descending:$true |

where {$excludeNames -notcontains $_.Name} |

Select-Object -ExpandProperty Name -First 1


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could use the -notcontains operator.

$excludeNames = 'datastore1','datastore2','datastore3'

Get-Cluster MyClus |

Get-Datastore |

Sort-Object -Property {$_.FreeSpaceGB} -Descending:$true |

where {$excludeNames -notcontains $_.Name} |

Select-Object -ExpandProperty Name -First 1


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much Smiley Happy

Reply
0 Kudos