SebSop
Contributor
Contributor

Merging two commands for getting VM information (CPU, RAM, DISK Space)

Jump to solution

Hello Community

I need a script that exports VM information of certain tagged VMs.

I need configured OS, CPU, RAM and used storage (summed up).

I managed to get the configured OS, CPU and RAM information with this line:

Get-VM | where {(Get-TagAssignment -Entity $_ | Select -ExpandProperty Tag) -like 'Tag1*'} | Select Name,@{N=”Configured OS”;E={$_.ExtensionData.Config.GuestFullname}}, NumCpu, MemoryGB

This line works and delivers exactly what I need.

Collecting the storage informartion was a bit more tricky but I managed to get it how I need it with this line:

Get-VM | where {(Get-TagAssignment -Entity $_ | Select -ExpandProperty Tag) -like 'Tag1*'} | Select-Object Name,@{n="HardDiskSizeGB"; e={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}

this line delivers the summed up amount of disk space used by each vm.

I would like to merge these two lines into one by adding the part behind the Tag but I always get error like:

Select-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:1 char:114
+ Get-VM | where {(Get-TagAssignment -Entity $_ | Select -ExpandProperty Tag) -lik ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

Please help me making one working line out of these two...

I need to export the result to csv or excel, but I will figure that out by myself once I have the main part of the script working. 

Thank you in advance 

 

SebSop

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You didn't show your combined code, but did you try something like this?

Get-VM |
where{(Get-TagAssignment -Entity $_).Tag.Name -match "^Tag1"} |
Select Name,
    @{N=”Configured OS”;E={$_.ExtensionData.Config.GuestFullname}}, 
    NumCpu, MemoryGB,
    @{N="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership

You didn't show your combined code, but did you try something like this?

Get-VM |
where{(Get-TagAssignment -Entity $_).Tag.Name -match "^Tag1"} |
Select Name,
    @{N=”Configured OS”;E={$_.ExtensionData.Config.GuestFullname}}, 
    NumCpu, MemoryGB,
    @{N="HardDiskSizeGB"; E={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum}}


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

View solution in original post

SebSop
Contributor
Contributor

Hello LucD

 

this did the trick.

My fault was that I thought I had to use both commands System Name (for CPU etc.) and System-Objekt Name (for storage) as they are different.

Your merge worked perfectly for me.

Thank you very much!

0 Kudos