VMware Cloud Community
momox1
Contributor
Contributor
Jump to solution

Inventory by storageclasse based on datastore TAGS.

Hello guys, I hope you are doing well.

I have some issues with one of the codes. I'm trying to get a vm inventory with the associated storage class and the provisioned space from that storage class.

I'm using a single storageclass category and different tags"( based on storage class, Bronze, platinum ,,,. I'm only tagging the datastores.

When I execute the single line get-vm  vm11  |Get-Datastore |Get-TagAssignment  I get the desired output, but with the code below, I'm always getting " com.vmware.cis.tagging.TagAssociationModel" as output 😞

At the end , the goal  is to find a way to get the provisioned space for a VM by storageClass and not having a line per vmdk. (hdsizeGB)

 

Thank you

####

Get-VM -PipelineVariable vm |
ForEach-Object {
Get-HardDisk -VM $vm |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $vm.Name
StorageClass = get-vm $vm |Get-Datastore |Get-TagAssignment
NumCpu = $vm.NumCpu
MemoryGB = $vm.MemoryGB
HDName = $_.Name
HDFilename = $_.Filename
HDSizeGB = $_.CapacityGB
PowerState = $vm.powerstate

})
}
}

 

 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This should give the GB used per Datastore (and the Tag name).

Get-VM -PipelineVariable vm |
ForEach-Object {
  Get-HardDisk -VM $vm |
  Group-Object -Property {$_.Filename.Split(']')[0].TrimStart('[')} |
  ForEach-Object -Process {
    New-Object -TypeName PSObject -Property ([ordered]@{
        VM = $vm.Name
        Datastore = $_.Name
        StorageClass = (Get-Datastore -Name $_.Name | Get-TagAssignment).Tag.Name
        NumCpu = $vm.NumCpu
        MemoryGB = $vm.MemoryGB
        HDSizeGB = ($_.Group | Measure-Object -Property capacityGB -Sum).Sum
        PowerState = $vm.powerstate
      })
  }
}


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

How did you tag those datastores?
And which vSphere version are you on?


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

0 Kudos
momox1
Contributor
Contributor
Jump to solution

Hello Lucd

 

I'm tagging them directly via the vCenter manually based on a naming convention and the storage class one the Datastore is created the 1st time.

The thing is that i'm trying to get something like the view of storage policy on vcloud director.

On vcloud director is it easy as with the vdc concept you can get that information easily.

I'm currently using

vSphere Client version 7.0.3.01100

 

Thank you

0 Kudos
momox1
Contributor
Contributor
Jump to solution

I've solved the com.vmware.cis.tagging.TagAssociationModel issue by adding the  , get-vm  vm11  |Get-Datastore |Get-TagAssignment |Select-object Tag

Now I have to figure out how to concatenate the HDSizeGB based on the tag assigned to the datastore.

 

for example If tag = GOLD  do the total of vmdks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry but I don't see tags on datastores with the Get-TagAsignment cmdlet


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

0 Kudos
momox1
Contributor
Contributor
Jump to solution

I'm doing basically this: In Tags & CustomAttributes

 

momox1_0-1685542009167.png

 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This should give the GB used per Datastore (and the Tag name).

Get-VM -PipelineVariable vm |
ForEach-Object {
  Get-HardDisk -VM $vm |
  Group-Object -Property {$_.Filename.Split(']')[0].TrimStart('[')} |
  ForEach-Object -Process {
    New-Object -TypeName PSObject -Property ([ordered]@{
        VM = $vm.Name
        Datastore = $_.Name
        StorageClass = (Get-Datastore -Name $_.Name | Get-TagAssignment).Tag.Name
        NumCpu = $vm.NumCpu
        MemoryGB = $vm.MemoryGB
        HDSizeGB = ($_.Group | Measure-Object -Property capacityGB -Sum).Sum
        PowerState = $vm.powerstate
      })
  }
}


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

0 Kudos
momox1
Contributor
Contributor
Jump to solution

That does the work. You're the man ^^

0 Kudos