
Last week I made a blog post about how you can create a USB drive for Windows To Go. In my post I used diskpart.exe to format the USB drive. Now we don’t live in the stone age anymore, so I did the same with the new version of Windows PowerShell coming in Windows 8 and Windows Server 8.
Now here some basic cmdlets to do some simple storage operations, like clean a disk, create a partition and so on.
Lets start simple
List all disks
Get-Disk
Now get all partitions
Get-Partition
Now get all partitions of disk 0
Get-Partition -DiskNumber 0
Clear a Disk
Get-Disk 1 | Clear-Disk -RemoveData
Create a new partition
New-Partition -DiskNumber 1 -UseMaximumSize
Format this volume
Get-Partition -DiskNumber 1 -PartitionNumber 1 | Format-Volume -FileSystem NTFS
Create new partition and format it with the label “USB”:
New-Partition -DiskNumber 1 -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel USB
Change driveletter
Set-Partition -DriveLetter E -NewDriveLetter T
Set a partition active
Set-Partition -DriveLetter T -IsActive $ture
Remove a partition
Remove-Partition -DriveLetter T
Bring a disk online
Set-Disk 1 -isOffline $false
Remove Readonly flag
Set-Disk 1 -isReadOnly $false
Initialize Disk with GPT
Initialize-Disk 1 -PartitionStyle GPT
This is some basic knowledge about the storage module in PowerShell v3. Lets see how we can change the commands from using diskpart to Windows PowerShell.
Diskpart.exe
select disk 1 clean create partition primary format fs=ntfs quick active assign letter=e
PowerShell:
Get-Disk 1 | Clear-Disk -RemoveData New-Partition -DiskNumber 1 -UseMaximumSize -IsActive -DriveLetter E | Format-Volume -FileSystem NTFS -NewFileSystemLabel USB












