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

How to format a partition (not a volume) using PowerShell?

我正在尝试以编程方式格式化分区。到目前为止,我已经尝试使用 PowerShell 来执行此操作,但似乎需要 "volume" 才能执行此操作。

要获得我想要格式化的分区,我使用这个:

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

接下来我应该如何格式化它?

注意

我无法使用

格式化分区
Format-Volume -Partition $partition -FileSystem NTFS

这是我得到的:

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

Get-Partition returns 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