我正在尝试以编程方式格式化分区。到目前为止,我已经尝试使用 PowerShell 来执行此操作,但似乎需要一个“卷”才能执行此操作。
要获得我想要格式化的分区,我使用这个:
$partition = get-disk -number 3 | get-partition | where Guid -eq "{0cdf62cf-64ac-468c-8d84-17292f3d63b7}"
接下来我应该如何格式化它?
注意
我无法使用
格式化分区Format-Volume -Partition $partition -FileSystem NTFS
这是我得到的:
这可能会有帮助。它是 $partition
的内容。如您所见,它没有
最佳答案
Get-Partition
返回类型为 CimInstance
的对象。所以您可以将它与 Format-Volume
一起使用。检查文档:https://learn.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
关于powershell - 如何使用 PowerShell 格式化分区(不是卷)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55222465/