是否有人知道从自定义对象中“破坏”哈希表源代码的方法。自定义对象上没有.getenumerrator,但我有以下哈希表:@{0=0.05;1024=0.050;51200=0.050;512000=0.050;1024000=0.045;5120000=0.037}。我正在通过Azure RateCard REST提取这一信息,并需要对其进行分解,这样我就可以访问每个级别的费率,从而生成一个准确的使用成本报告。有什么建议吗?抽样产出:
MeterId : d23a5753-ff85-4ddf-af28-8cc5cf2d3882
MeterName : Standard IO - Page Blob/Disk (GB)
MeterCategory : Storage
MeterSubCategory : Locally Redundant
Unit : GB
MeterTags : {}
MeterRegion :
MeterRates : @{0=0.05; 1024=0.050; 51200=0.050; 512000=0.050; 1024000=0.045; 5120000=0.037}
EffectiveDate : 2014-02-01T00:00:00Z
IncludedQuantity : 0.0
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
EffectiveDate NoteProperty System.String EffectiveDate=2014-02-01T00:00:00Z
IncludedQuantity NoteProperty System.Decimal IncludedQuantity=0.0
MeterCategory NoteProperty System.String MeterCategory=Storage
MeterId NoteProperty System.String MeterId=d23a5753-ff85-4ddf-af28-8cc5cf2d3882
MeterName NoteProperty System.String MeterName=Standard IO - Page Blob/Disk (GB)
MeterRates NoteProperty System.Management.Automation.PSCustomObject MeterRates=@{0=0.05; 1024=0.050; 51200=0.050; 512000=0.050; 1024000=0.045; 5120000=0.037}
MeterRegion NoteProperty System.String MeterRegion=
MeterSubCategory NoteProperty System.String MeterSubCategory=Locally Redundant
MeterTags NoteProperty System.Object[] MeterTags=System.Object[]
Unit NoteProperty System.String Unit=GB 发布于 2015-12-01 17:24:14
在类似的问题上找到了这段代码。解决了我的问题:
$js | Get-Member -MemberType NoteProperty).Name发布于 2015-11-25 22:39:57
不知道你所说的破门而入是什么意思,但这应该给你钥匙:
$object.MeterRates.keys这将为您提供以下值:
$object.MeterRates.keys | % {$object.MeterRates[$_]}你想要的是总价值吗?我猜可能是这样的:
($object.MeterRates.keys | % {$object.MeterRates[$_] * $_} | Measure-Object -Sum).Sum发布于 2015-11-25 22:40:01
也许有更好的方法,但我的特定版本的powershell黑客产生了这样的东西-
$a = "@{0=0.05; 1024=0.050; 51200=0.050; 512000=0.050; 1024000=0.045; 5120000=0.037}"
$b = ConvertFrom-StringData `
-StringData $a.Replace("; ","`n").Replace("@","").Replace("{","").Replace("}","")这假定整个字符串是可用的,用换行符替换分号,丢弃其他位,并将其交给。
https://stackoverflow.com/questions/33926917
复制相似问题