Adding output from loop to hash table powershell
I have the following code,
#Pull the number of Physical Drives
$phy = $datafile.GetEnumerator()|Where-Object {$_.name -like "*Physical*"}
[array]$phydisks = ($phy.name | Sort-Object )
#For each of these drives work work out the physical make up of the disk
$drives= ForEach($_ in $phydisks){
$cylinders = $datafile["$_"]["Cylinders"]
$head = $datafile["$_"]["TracksPerCylinder"]
$sectors = $datafile["$_"]["SectorsPerTrack"]
$bytespersector = $datafile["$_"]["BytesPerSector"]
#Convert the output to gigabites and round up the the next decimal place
$physicaldrivegb = ((([int]$cylinders * [int]$head * [int]$sectors *
[int]$bytespersector) / 1024) / 1024) /1024
$physicaldrivesize = [math]::Round($physicaldrivegb,1)
}
$vmwarefile = @{ServerName=$servername;Memory =
$servermemorymb;number_of_processors =
$processorcount;'number_of_cores/processor' =
$processorcorecount;number_of_disks = $numberofdisks}
#CAdd disk number and size to $vmwarefile hash
$i = 0
ForEach($d in $drives){
$vmwarefile.Add('Disk'+$i++, $d)
}
I can't get it to loop through and add the results of Disk'+$i++ as Key
and $d as the hash value. Is there a way to do this?
No comments:
Post a Comment