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

标签 powershell partitioning

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

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

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

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

注意

我无法使用

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

这是我得到的:

enter image description here

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

enter image description here

最佳答案

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/

相关文章:

mysql - 在 MySQL 分区表上选择未选择正确的分区

mysql - 分区时如何处理外键

powershell - 无法在脚本模块中创建 PowerShell 别名

scripting - 是否可以将Powershell配置文件代码设置为在每个脚本之后运行?

json - 在Powershell中过滤JSON

powershell - 如何使用 Powershell 从注册表中的值获取数据

java - Quicksort 3 方式分区代码没有按要求执行

Athena 中按日期列分区

algorithm - 将整数数组分成 K 组,使得每组具有最小范围

powershell - v5特殊方法 `New`与静态方法 `New`冲突