如何使用PowerShell格式化分区(而不是卷)?

问题描述 投票:3回答:1

我正在尝试以编程方式格式化分区。到目前为止,我已经尝试过PowerShell来做这件事,但似乎需要一个“量”才能这样做。

要获取我要格式化的分区,我使用:

$partition = get-disk -number 3 | get-partition | where Guid -eq "{0cdf62cf-64ac-468c-8d84-17292f3d63b7}"

我接下来应该怎么做呢?

NOTE

我无法使用格式化分区

Format-Volume -Partition $partition -FileSystem NTFS

这就是我得到的:

enter image description here

这可能会有所帮助。这是$partition的内容。如你所见,它没有

enter image description here

powershell partitioning
1个回答
2
投票

Get-Partition返回CimInstance类型的对象。所以你可以和Format-Volume一起使用它。检查文档:https://docs.microsoft.com/en-us/powershell/module/storage/format-volume?view=win10-ps

PS X:\> $partition = get-disk -number 0 | get-partition | Where DriveLetter -eq "D"
PS X:\> $partition.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     CimInstance                              System.Object
PS X:\> Format-Volume -Partition $partition -FileSystem NTFS
© www.soinside.com 2019 - 2024. All rights reserved.