Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active May 28, 2016 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/3755ade7430fef73964d3f124430acf3 to your computer and use it in GitHub Desktop.
Save guitarrapc/3755ade7430fef73964d3f124430acf3 to your computer and use it in GitHub Desktop.
Don't use Diskpart anymore. Please to all.
$diskName = "Crucial";
$driveLetter = "D";
Get-Disk | where FriendlyName -match $diskName | Clear-Disk -RemoveData -RemoveOEM -PassThru | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -UseMaximumSize -DriveLetter $driveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel Volume -Force;
<#
# Output Sample
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- --------------- ---------- --------- ------------ ----------------- ------------- ----
D Volume NTFS Fixed Healthy OK 465.61 GB 465.76 GB
#>
# may better add | where BootFromDisk -eq $false like following
Get-Disk | where FriendlyName -match $diskName | where BootFromDisk -eq $false | Clear-Disk -RemoveData -RemoveOEM -PassThru | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -UseMaximumSize -DriveLetter $driveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel Volume -Force;
@guitarrapc
Copy link
Author

guitarrapc commented May 28, 2016

Sample

Get-Disk `
| where FriendlyName -Match ST3500 `
| Clear-Disk -RemoveData -RemoveOEM -PassThru `
| Initialize-Disk -PartitionStyle MBR -PassThru `
| New-Partition -UseMaximumSize -AssignDriveLetter `
| Format-Volume -FileSystem NTFS -Force

<#
DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining      Size
----------- --------------- ---------- --------- ------------ ----------------- -------------      ----
F                           NTFS       Fixed     Healthy      OK                    465.61 GB 465.76 GB
#>

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment