Adding output from loop to hash table powershell -
i have following code,
#pull 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 physical make of disk $drives= foreach($_ in $phydisks){ $cylinders = $datafile["$_"]["cylinders"] $head = $datafile["$_"]["trackspercylinder"] $sectors = $datafile["$_"]["sectorspertrack"] $bytespersector = $datafile["$_"]["bytespersector"] #convert output gigabites , round 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 , size $vmwarefile hash $i = 0 foreach($d in $drives){ $vmwarefile.add('disk'+$i++, $d) }
i can't loop through , add results of disk'+$i++ key , $d hash value. there way this?
$count=1 $h=@{} foreach($_ in $phydisks){ $cylinders = $datafile["$_"]["cylinders"] $head = $datafile["$_"]["trackspercylinder"] $sectors = $datafile["$_"]["sectorspertrack"] $bytespersector = $datafile["$_"]["bytespersector"] $physicaldrivegb = ((([int]$cylinders * [int]$head * [int]$sectors * [int]$bytespersector) / 1024) / 1024) /1024 $physicaldrivesize = [math]::round($physicaldrivegb,1) $h."disk$($count)" = $physicaldrivesize $count+=1 } $h
Comments
Post a Comment