代码之家  ›  专栏  ›  技术社区  ›  SuperJMN

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

  •  2
  • SuperJMN  · 技术社区  · 7 年前

    我正在尝试以编程方式格式化分区。到目前为止,我已经尝试过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

    1 回复  |  直到 7 年前
        1
  •  2
  •   Fourat    7 年前

    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
    
    推荐文章