Accessing elements of hashtable, what am I doing wrong?


hello,

i have hashtable of hashtable $a. want format information both freespacenow , originalfreespace appearing values in table , having hard time understanding going on output

ps c:\users\gs> $a    name                           value  ----                           -----  d:                             {freespacenow, originalfreespace}  c:                             {freespacenow, originalfreespace}

if format output below output not change @ regardless put after "select" statement, no errors no change in output, why that?

ps c:\users\gs> $a | select  $_.namsdfdsf    name                           value  ----                           -----  d:                             {freespacenow, originalfreespace}  c:                             {freespacenow, originalfreespace}  

secondly how achieve put both numbers in table? 

ps c:\users\gs> $a | select $_.sad ,  @{n= "dd"; e = $_.item["freespacenow"]}  [ : cannot index null array.  @ line:1 char:46  + $a | select $_.sad ,  @{n= "dd"; e = $_.item[ <<<< "freespacenow"]}      + categoryinfo          : invalidoperation: (freespacenow:string) [], runtimeexception      + fullyqualifiederrorid : nullarray  

i see.  have hashtable of hashtables; can work that.  enumerate items in hashtable (in powershell), have call getenumerator() method explicitly, or use keys or values properties (getenumerator() more efficient option).  when that, list of keyvaluepair objects key , value properties (key "c:" or "d:" drive letter, , value refer inner hashtable contains freespacenow , originalfreespace keys).  example:

$a.getenumerator() | select-object -property @(     @{ name = 'driveletter'; expression = { $_.key } }     @{ name = 'freespacenow'; expression = { $_.value['freespacenow'] } }     @{ name = 'originalfreespace'; expression = { $_.value['originalfreespace'] } } ) 



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file