Powershell Get-PartitionSupportedSize失败,出现错误
以下是我正在使用的命令:Powershell Get-PartitionSupportedSize失败,出现错误,powershell,partition,Powershell,Partition,以下是我正在使用的命令: for $disk in Get-Disk $driveLetter = (Get-Partition -DiskNumber $disk.Number | where {$_.DriveLetter}).DriveLetter $partitionNum = (Get-Partition -DriveLetter $driveLetter).PartitionNumber $allowedSize = (Get-PartitionSupport
for $disk in Get-Disk
$driveLetter = (Get-Partition -DiskNumber $disk.Number | where {$_.DriveLetter}).DriveLetter
$partitionNum = (Get-Partition -DriveLetter $driveLetter).PartitionNumber
$allowedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -PartitionNumber $partitionNum).SizeMax
Write-verbose "Total Partition Size allowed: $allowedSize"
以下是堆栈:
Get-PartitionSupportedSize : Failed
Activity ID: {a5e65922-521b-46c4-aac8-047ea73a3790}
At C:\extendPartition.ps1:30 char:25
+ ... owedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -Part ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (StorageWMI:ROOT/Microsoft/.../MSFT_Partition) [Get-PartitionSupportedSize], CimException
+ FullyQualifiedErrorId : StorageWMI 4,Get-PartitionSupportedSize
获取PartitionSupportedSize:失败
活动ID:{a5e65922-521b-46c4-aac8-047ea73a3790}
在C:\extendPartition.ps1:30字符:25
+ ... owedSize=(Get-PartitionSupportedSize-DiskNumber$disk.Number-Part。。。
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:NotSpecified:(StorageWMI:ROOT/Microsoft/../MSFT\u Partition)[Get PartitionSupportedSize],CimException
+FullyQualifiedErrorId:StorageWMI 4,Get-PartitionSupportedSize
无法找到任何好的链接相同,所以任何线索是感激的
编辑:很抱歉漏掉了一些东西。所以我修改了代码以显示我正在尝试的内容。正如您所看到的,我正在尝试只打印允许的大小。
接下来,Get-PartitionSupportedSize函数在Windows 10虚拟机上出现故障
这对我有用
$PartitionNum=3 #or whatever You need
foreach ($disk in Get-Disk)
{
$allowedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -PartitionNumber $partitionNum).SizeMax
}
然而:
将在循环的每一圈中被覆盖$allowedSize
只定义一次。如果要循环所有分区,可能需要执行类似于$partitionNum
Get Partition | select-Property PartitionNumber,DriveLetter,type,@{n='sizemax';e={($| Get PartitionSupportedSize).sizemax},@{n='sizemin';e={($| Get PartitionSupportedSize).sizemin}
- 很少有小事情
这对我有用
$PartitionNum=3 #or whatever You need
foreach ($disk in Get-Disk)
{
$allowedSize = (Get-PartitionSupportedSize -DiskNumber $disk.Number -PartitionNumber $partitionNum).SizeMax
}
然而:
将在循环的每一圈中被覆盖$allowedSize
只定义一次。如果要循环所有分区,可能需要执行类似于$partitionNum
Get Partition | select-Property PartitionNumber,DriveLetter,type,@{n='sizemax';e={($| Get PartitionSupportedSize).sizemax},@{n='sizemin';e={($| Get PartitionSupportedSize).sizemin}
get PartitionSupportedSize
将分区类型链接到文件大小时遇到了一点困难
输入
输出
既然有人给了你一个修复代码的答案,我想我应该给你的作品,不包括分区类型。在尝试从
get PartitionSupportedSize
将分区类型链接到文件大小时遇到了一些困难
输入
输出
设置服务-名称defragsvc-StartupType手册
修复此问题。设置服务-名称defragsvc-StartupType手册
解决此问题。首先,for循环的格式不正确,如果在同一个驱动器上有多个分区,则会出现错误,这些分区都将以字节为单位,如何将get disk-friendly名称与sizemax匹配?如果您想解决这个问题并从那里开始,我会很感激。如果您想要答案,jus不要问。首先,for循环的格式不正确,如果在同一个驱动器上有多个分区,就会出现错误,它们都将以字节为单位,如何将get-disk-friendly名称与sizemax匹配?如果您想解决这个问题并从那里开始,我很感激。如果您想要答案,只需询问virtual.onl Machine,您的代码为我提供以下输出:SizeMin SizeMax FriendlyName-------------------------0 0 VMware虚拟磁盘0 0 VMware虚拟磁盘在虚拟机上,您的代码为我提供以下输出:SizeMin SizeMax FriendlyName---------------0 0 VMware虚拟磁盘0 0 VMwar虚拟磁盘
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