Get-PartitionSupportedSize is failing with error

The name of the picture


Get-PartitionSupportedSize is failing with error



Here is the command which I am using:


for $disk in Get-Disk
$allowedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -PartitionNumber $partitionNum).SizeMax



Here is the stack:



Not able to find any good links for the same, so any leads are appreciated.





First, your for loop is formatted incorrectly, your going to have errors if you have multiple partitions on the same drive, they are all going to be in bytes, How are you going to match the get-disk friendly name with the sizemax? If you want to work it out and go from there, I can appreciate that. If you want the answer, just ask.
– Drew Lean
7 hours ago




2 Answers
2



Few small things
This worked for me


$PartitionNum=3 #or whatever You need
foreach ($disk in Get-Disk)
{
$allowedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -PartitionNumber $partitionNum).SizeMax
}



However:


$allowedSize


$partitionNum


Get-Partition |select -Property PartitionNumber, DriveLetter, type ,@{n='sizemax';e={($_|Get-PartitionSupportedSize).sizemax}}, @{n='sizemin';e={($_|Get-PartitionSupportedSize).sizemin}}



Well since someone gave you an answer to fix your code, I thought I should give you the works, minus the partition types. Was having a bit of a hard time trying to link the partition types to the file size from the get-PartitionSupportedSize.


get-PartitionSupportedSize



Input


$AllowedSize = @()

Foreach($Disk in (Get-Disk)){
$Output = (get-PartitionSupportedSize -DiskNumber $disk.Number)
If($Output.count -gt 1){
Foreach($HDD in $Output){
$HDD.SizeMax = ([math]::round($HDD.sizemax/1GB, 2));$HDD.SizeMin = ([math]::round($HDD.sizemin/1GB, 2))
$Output | Add-Member -NotePropertyName FriendlyName -NotePropertyValue $disk.FriendlyName -Force
}
} Else {
$Output.SizeMax = ([math]::round($Output.sizemax/1GB, 2));$Output.SizeMin = ([math]::round($Output.sizemin/1GB, 2))
$Output | Add-Member -NotePropertyName FriendlyName -NotePropertyValue $disk.FriendlyName -Force
}
$AllowedSize += $Output
}
$AllowedSize



Output


SizeMin SizeMax FriendlyName
------- ------- ------------
0.1 0.1 NVMe Samsung SSD 960
0.44 0.44 NVMe Samsung SSD 960
0.02 0.02 NVMe Samsung SSD 960
461.26 465.21 NVMe Samsung SSD 960
3.05 111.79 Samsung SSD 840 EVO 120GB
0.12 0.12 ST2000DM006-2DM164
1169.37 1662.89 ST2000DM006-2DM164
130.03 200 ST2000DM006-2DM164






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP