Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
Owner

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