0

Does anyone have know of a way to "break" open a hash table source from a custom object. There is no .getenumerrator on a custom object but I have this hashtable: @{0=0.05; 1024=0.050; 51200=0.050; 512000=0.050; 1024000=0.045; 5120000=0.037}. I am pulling this information via the Azure RateCard REST API and need to break it down so I have access to each tier of rates to generate an accurate report of usage cost. Any suggestions? Sample outputs:

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                         
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
Monty Harris
  • 59
  • 1
  • 5

3 Answers3

1

Not sure what it is you mean by break open but this should give you the keys:

$object.MeterRates.keys

This will give you the values:

$object.MeterRates.keys | % {$object.MeterRates[$_]}

Are you after the total value? I guessing it might be something like this:

($object.MeterRates.keys | % {$object.MeterRates[$_] * $_} | Measure-Object -Sum).Sum
Dave Sexton
  • 10,768
  • 3
  • 42
  • 56
  • Keys? Not sure what value you are referring to there. – Monty Harris Nov 30 '15 at 23:29
  • Keys are exactly what you would want--IF the MeterRates was a plain hash table. So I do suggest you bookmark @DaveSexton's answer for future reference, as it will come in handy as you learn PowerShell. (Dave: if you look at his input you'll see it is a custom object not a plain hash table, so Monterey's posted answer is, in fact, necessary, for this particular question.) – Michael Sorens Dec 03 '15 at 04:30
0

There's probably a better way to do this but my particular version of powershell hacking produced something like this -

$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("}","")

This presumes that the entire string is available, replace the semicolons with newlines, ditches the other bits and give it to ConvertFrom-StringData

Michael B
  • 11,887
  • 6
  • 38
  • 74
0

Found this code on a similar question. Solves my problem:

$js | Get-Member -MemberType NoteProperty).Name
thatOneGuy
  • 9,977
  • 7
  • 48
  • 90
Monty Harris
  • 59
  • 1
  • 5