sde94
Contributor
Contributor

Using variables in 'get-stat' powercli command

Jump to solution

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
2 Replies
LucD
Leadership
Leadership

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

0 Kudos
sde94
Contributor
Contributor

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.

0 Kudos