How to map which volume resides on which partition in Windows?
Solution 1:
One possible solution, is the following power shell script. Output should be in JSON format. The problem with this solution is that it relies on the get-partition cmdlet. This cmdlet was introduced after windows 2008R2. This would work as a solution if the get-partition cmdlet were to be ported to windows 2008R2, or if I found a solution that would do the same thing on windows 2008R2. Although not a complete solution, it didn't fit as a comment.
$CimPartInfo = get-partition
"{"
foreach ($CimPart in $CimPartInfo) {
if ($CimPart.Guid -eq $null) {
$PartGUID = [regex]::match($CimPart.AccessPaths, 'Volume({[^}]+})').Groups[1].Value
}
else {
$PartGUID = $CimPart.Guid
}
"`"$PartGUID`": {"
"`"DiskId`": $($CimPart.DiskNumber),"
"`"PartitionId`": $($CimPart.PartitionNumber),"
"`"Type`": `"$($CimPart.Type)`","
"`"Size`": $($CimPart.Size),"
"`"Offset`": $($CimPart.Offset),"
"`"GUID`": `"$($CimPart.Guid)`","
$x = $CimPart.IsBoot
"`"Bootable`": $($x.ToString().ToLower()),"
"`"Status`": `"$($CimPart.OperationalStatus)`""
if ($CimPart -eq $CimPartInfo[-1]){ "}"}
else {"},"}
} #foreach CimPart
"}"