0

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
}

#Add 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?

1 Answer 1

1
$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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.