Returning multiple values from simular hash keys powershell
I have the following code that pulls in some server information from a
text file and spits it into a hashtable.
Get-Content $serverfile | Foreach-Object {
if($_ -match '^([^\W+]+)\s+([^\.+]+)')
{
$sh[$matches[1]] = $matches[2]
}
}
$sh.GetEnumerator()| sort -Property Name
This produces the following;
Name Value
---- -----
Disk0 40
Disk1 40
Disk2 38
Disk3 43
Memory 4096
Name Value
Number_of_disks 1
Number_of_network_cards 2
Number_of_processors 1
ServerName WIN02
Depending on the server there may be one Disk0 or many more.
My challenge here is to pull each Disk* value from each of the varying
number of Disk keys and return the values in a comma separated list, for
example;
$disks = 40,40,38,43
I have tried varying approaches to this problem however none have met the
criteria of being dynamic and including the ',' after each disk.
Any help would be appreciated.
No comments:
Post a Comment