Jump to content
Software FX Community

Hashtable chart


dGnabasik
 Share

Recommended Posts

# This simple hashtable chart produces the error:

#Add-Member : Cannot bind argument to parameter 'Name' because it is null.

#At line:5 char:70 + add-member -inputobject $aItem -membertype NoteProperty -Name <<<<  $entry.Key -value $entry.Count

# What am I doing wrong? Thanks.

 

# Test for snapin already registered with session; add it if not.

$Variable = Get-PSSnapIn 'PowerGadgets' -ErrorAction SilentlyContinue

if (!$Variable)

{

 add-pssnapin PowerGadgets

}

$names = "Not given ", "ECO.Level1", "ECO.Level2", "ECO.Level3", "ECO.Level4"

$levels = 3, 2, 4, 1, 5

$entries = new-object -typename System.Collections.Hashtable

foreach ($i in 0..$NUMITEMS) {

 $entries.Add($names[$i], $levels[$i])

}

$block = {

  $aItem = new-object object

 add-member -inputobject $aItem -membertype NoteProperty -Name Name -value "ECO Levels"

 foreach ($entry in $entries) { # DictionaryEntry.Key,Value

add-member -inputobject $aItem -membertype NoteProperty -Name $entry.Key -value $entry.Count  # or $entry.Value

 }

  write-output $aItem

}  # block

&$block | out-chart -title "ECO Levels Report" -View3D_Enabled true -view3D_rotated true -Palette "ChartFX6.EarthTones"

&$block | out-chart -title "Event Log Report" -Series_3_Color Green -Series_2_Color Red -Series_1_Color Blue -Series_0_Color Orange

Link to comment
Share on other sites

foreach ($i in 0..$NUMITEMS) {

add-member -inputobject $aItem -membertype NoteProperty -Name $entry.Key -value $entry.Count  # or $entry.Value

 

I've just left 2 lines of interest...  I'm not sure where you get $NUMITEMS.  Would that be this instead:

foreach($i in 0..$names.count)

That may still leave you with an offset of 1.

For your add-member command, I believe you should have:

...-name $entry.keys -value $entry.values

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...