Powershell聚合嵌套数组值
如何将平均值列收集为平均值 最接近我的是:Powershell聚合嵌套数组值,powershell,Powershell,如何将平均值列收集为平均值 最接近我的是: $metric_result | Format-Table -Property @{label='Name';e={$_.Name.Value}},Unit,@{label='Average';e={$_.Data.Average}} Name Unit Average ---- ---- --- Percentage CPU
$metric_result | Format-Table -Property @{label='Name';e={$_.Name.Value}},Unit,@{label='Average';e={$_.Data.Average}}
Name Unit Average
---- ---- ---
Percentage CPU Percent {$null, $null, $null, $null…}
Disk Read Operations/Sec CountPerSecond {$null, $null, $null, $null…}
我希望得到一个最终输出,如下所示:
Name Unit Average
---- ---- ----
Percentage CPU Percent 0.234
Disk Read Operations/Sec CountPerSecond 0.043
TimeStamp : 7/30/2019 11:39:00 PM
Average : 0.292142857142857
Minimum :
Maximum :
Total :
Count :
我有一个powershell System.Array,$metric\u result
,看起来像这样:
Id : /my/special/id
Name :
LocalizedValue : Percentage CPU
Value : Percentage CPU
Type : Microsoft.Insights/metrics
Unit : Percent
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
Id : /my/special/id2
Name :
LocalizedValue : Disk Read Operations/Sec
Value : Disk Read Operations/Sec
Type : Microsoft.Insights/metrics
Unit : CountPerSecond
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
$metric_result | ForEach-Object {
[PSCustomObject]@{
ID = $_.ID
Name = $_.Name.LocalizedValue
Unit = $_.Unit
Average = "{0:N3}" -f ($_.Data.Average|Measure -Ave).Average
}
}
$metric\u result.Data
字段是一组值,如下所示:
Name Unit Average
---- ---- ----
Percentage CPU Percent 0.234
Disk Read Operations/Sec CountPerSecond 0.043
TimeStamp : 7/30/2019 11:39:00 PM
Average : 0.292142857142857
Minimum :
Maximum :
Total :
Count :
试着这样做:
Id : /my/special/id
Name :
LocalizedValue : Percentage CPU
Value : Percentage CPU
Type : Microsoft.Insights/metrics
Unit : Percent
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
Id : /my/special/id2
Name :
LocalizedValue : Disk Read Operations/Sec
Value : Disk Read Operations/Sec
Type : Microsoft.Insights/metrics
Unit : CountPerSecond
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
$metric_result | ForEach-Object {
[PSCustomObject]@{
ID = $_.ID
Name = $_.Name.LocalizedValue
Unit = $_.Unit
Average = "{0:N3}" -f ($_.Data.Average|Measure -Ave).Average
}
}
试着这样做:
Id : /my/special/id
Name :
LocalizedValue : Percentage CPU
Value : Percentage CPU
Type : Microsoft.Insights/metrics
Unit : Percent
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
Id : /my/special/id2
Name :
LocalizedValue : Disk Read Operations/Sec
Value : Disk Read Operations/Sec
Type : Microsoft.Insights/metrics
Unit : CountPerSecond
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
$metric_result | ForEach-Object {
[PSCustomObject]@{
ID = $_.ID
Name = $_.Name.LocalizedValue
Unit = $_.Unit
Average = "{0:N3}" -f ($_.Data.Average|Measure -Ave).Average
}
}
在尝试了前面的一些答案并阅读了有关为每个InputObject创建计算属性的内容后,这就是我要做的工作
$average = @{l="Average";e={($_.Data.Average | Measure-Object -Average).Average}}
$local_name = @{l='Name';e={$_.Name.LocalizedValue}}
$metric_result | Select-Object -Property $local_name,Unit,$average
Name Unit Average
---- ---- ----
Percentage CPU Percent 0.234
Disk Read Operations/Sec CountPerSecond 0.043
在尝试了前面的一些答案并阅读了有关为每个InputObject创建计算属性的内容后,这就是我要做的工作
$average = @{l="Average";e={($_.Data.Average | Measure-Object -Average).Average}}
$local_name = @{l='Name';e={$_.Name.LocalizedValue}}
$metric_result | Select-Object -Property $local_name,Unit,$average
Name Unit Average
---- ---- ----
Percentage CPU Percent 0.234
Disk Read Operations/Sec CountPerSecond 0.043
您是否可以共享
$metric\u结果的输出。数据
您是否可以共享$metric\u结果的输出。数据
数据是具有平均属性的对象的集合。目的是找到该值的平均值。我知道。太多称为AverageData的东西是具有Average属性的对象的集合。目的是找到该值的平均值。我知道。太多的东西被称为“平均值”,你的问题有一些变化,切换到LocalizedValue,添加ID。我很好奇我的更改后的答案是否会产生相同的结果。没错,我会更新到原始的简化问题。你的问题有一些变化,切换到LocalizedValue,添加了ID。我很好奇我修改后的答案是否会产生相同的结果。没错,我会更新到原来的简化问题