如何使用 Powershell 设置(初始化、分区和格式化)磁盘?

Kyl*_*ndt 9 windows powershell windows-server-2012 powershell-v3.0

使用 powershell 设置新磁盘(初始化、分区和格式化)的基本示例是什么?

Kyl*_*ndt 17

步骤 1:列出系统可用的磁盘:

PS C:\> Enter-PSSession -ComputerName 192.168.1.193 -Credential administrator
PS C:\> Get-Disk

Number Friendly Name                            OperationalStatus                    Total Size Partition Style
------ -------------                            -----------------                    ---------- ---------------
0      Red Hat VirtIO SCSI Disk Device          Online                                    20 GB MBR
1      Red Hat VirtIO SCSI Disk Device          Offline                                    2 GB RAW
Run Code Online (Sandbox Code Playgroud)

第 2 步:初始化磁盘:

[192.168.1.193]: PS C:\Users\Administrator\Documents> Initialize-Disk -Number 1

磁盘现在将在重复时显示分区样式 (GBP) Get-Disk

1      Red Hat VirtIO SCSI Disk Device   Online    2 GB GPT
Run Code Online (Sandbox Code Playgroud)

第 3 步:设置分区

PS C:\> New-Partition -DiskNumber 1 -UseMaximumSize -AssignDriveLetter


Disk Number: 1

PartitionNumber  DriveLetter Offset        Size     Type
---------------  ----------- ------        ----     ----
2                D           33619968      1.97 GB  Basic
Run Code Online (Sandbox Code Playgroud)

第 4 步:格式化卷:

PS C:\> Format-Volume -DriveLetter D

Confirm
Are you sure you want to perform this action?
Warning, all data on the volume will be lost!
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "Y"): Y

DriveLetter       FileSystemLabel  FileSystem       DriveType        HealthStatus        SizeRemaining             Size
-----------       ---------------  ----------       ---------        ------------        -------------             ----
D                                  NTFS             Fixed            Healthy                   1.92 GB          1.97 GB
Run Code Online (Sandbox Code Playgroud)

请参阅存储 cmdlet以了解有关使用 powershell 进行磁盘管理的更多信息。