VMware Cloud Community
sde94
Contributor
Contributor
Jump to solution

Using variables in 'get-stat' powercli command

Hi,

I try to collect data via powershell and vsphere powercli I would like to pass several stat IDs at once using variable containing my stat ID list.

1) When I do this...

get-stat -entity(get-vmhost $host_id) -stat mem.active.average,sys.resourcecpuusage.average -realtime -maxsamples 1

... It works fine

2) When I do this...

$list = 'mem.active.average'

get-stat -entity(get-vmhost $host_id) -stat $list -realtime -maxsamples 1

... It works fine, I can pass variables and so a stat ID, one at a time.

3) When I do this...

$list = 'mem.active.average,sys.resourcecpuusage.average'

get-stat -entity(get-vmhost $host_id) -stat $list -realtime -maxsamples 1

... It does not work.Powercli returns ...The metric counter "mem.active.average,sys.resourcecpuusage.average" doesn't exist for entity...

I do not understand where the problem is when passing variables, any idea?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That should be

$list = "mem.active.average","sys.resourcecpuusage.average"
get-stat -entity(get-vmhost $host_id) -stat $list -realtime -maxsamples 1

You have to give an array of strings.


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

That should be

$list = "mem.active.average","sys.resourcecpuusage.average"
get-stat -entity(get-vmhost $host_id) -stat $list -realtime -maxsamples 1

You have to give an array of strings.


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

Reply
0 Kudos
sde94
Contributor
Contributor
Jump to solution

Perfect.

As I will have several stats unknown in advance in my program code I will use the '+=' operator to populate my array.

Thank you.

Reply
0 Kudos