1

I'm new to PWSH, it may looks easy for you guys but I can't find the way to show the result as expected.

$vm2 = Get-VM VM1234
$vmMemUsageAvg = get-VM $vm2.Name | Select @{N="Mem.Usage.Average";E={[Math]::Round((($_ |Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-24)-IntervalMins 5 -MaxSamples (12) |Measure-Object Value -Average).Average),2)}}

Now, as example, when requesting the result of $vmMemUsageAvg I receive this output:

C:\Windows\system32> $vmMemUsageAvg 
Mem.Usage.Average
-----------------
              5.9

but I want only want as output the value, like: 5.9

putting that in Excel cell with

$Sheet.Cells.Item($intRow, 13) = [String]$vmMemUsageAvg 

gives me a string like this:

@{Mem.Usage.Average=5.9}

Any help welcome to have this value ONLY displayed

4
  • putting that in Excel cell with $Sheet.Cells.Item($intRow, 13) = [String]$vmMemUsageAvg give me a string like this: @{Mem.Usage.Average=5.9} Commented Sep 12, 2017 at 19:37
  • You have made an object with a property called 'Mem.Usage.Average' and a value of 5.9 in that property. To see just the value of that property, you have to ask for just that property. $vmMemUsageAvg."Mem.Usage.Average". Yes, it's a bit silly to wrap 5.9 up in a property of an object, then unwrap it straight away afterwards. Commented Sep 12, 2017 at 19:45
  • Yes! I tried $vmMemUsageAvg.Mem.Usage.Average but wasn't successfull. THE QUOTE MAKE IT WORK. THANKS ! Commented Sep 12, 2017 at 19:50
  • @VinceD This is why you shouldn't include .'s in the names of properties. Without it quoted, it was looking in the a Mem property for the Usage property then into an Averaged property. Which is confusing Commented Sep 12, 2017 at 20:36

1 Answer 1

1

By using Select-Object @{N="Mem.Usage.Average";E={...}} you are making an object with a property Mem.Usage.Average, but it looks just want a string. So just take out the Select

$vm2 = Get-VM VM1234
$vmMemUsageAvg = [Math]::Round(((get-VM $vm2.Name | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-24)-IntervalMins 5 -MaxSamples (12) | Measure-Object Value -Average).Average),2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.