VMware Cloud Community
drivera01
Enthusiast
Enthusiast

exclude a datastore from reporting



how would i exclude a particular datastore name from reporting


get-vm $vmlist | select Name, @{N="Datastore free space (GB)";E={[string]::Join(',',[math]::Round((Get-Datastore -Id ($_.DatastoreIdList)).FreeSpaceGB))}} |


some of our vms have a vmswap datastore that is reporting.. I dont need to know about it


lets say datastore is called "datastore1"

thanks

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try something like

foreach($vm in get-vm $vmlist){
 
$ds = Get-Datastore -Id $vm.DatastoreIdList | where {$_.Name -ne "datastore1"}
 
$vm | Select Name,
 
@{N="DS";E={($ds | Select -ExpandProperty Name) -join ','}},
 
@{N="Datastore free space (GB)";E={
    [
string]::Join(',',($ds | %{[math]::Round($_.FreeSpaceGB,1)}))
  }}
}


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

0 Kudos
drivera01
Enthusiast
Enthusiast

Not sure if that will work..

Maybe how im asking is not right.

When do a basic command like:

Get-vm vm1 |get-datastore

The output is:

Datastore0 ….

Datastore1 ….

I notice that datastore1 only started showing up cause I did a svmotion of this vm today. Prior to that datastore1 never showed up.

I care less about datastore1 cause it is a vmswap datastore.

I added your code but I get a “0” in the cell where the free space should be for the vm datastore free space.

0 Kudos
drivera01
Enthusiast
Enthusiast



error I get when running this poprtion of code...

\vSphere PowerCLI> $ds = (Get-Datastore -Id $vm.DatastoreIdList) | where {$_.Name -ne "datastore1"}

 Cannot validate argument on parameter 'Id'. The argument is null or empty. Supply an argument that is not null or empty and then try the command ag

25

tastore -Id <<<<  $vm.DatastoreIdList) | where {$_.Name -ne "datastore1"}

nfo          : InvalidData: (Smiley Happy , ParameterBindingValidationException

ifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

0 Kudos
LucD
Leadership
Leadership

That seems to indicate that you have VMs that are only located on datastore1.

You can build in a test to check if the DatastoreIdList equals $null and if yes, skip the next lines


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

0 Kudos