
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













Pingback: Haftanın Sonu Bölüm 5: 15/4/12 | Sanallaştırma ve Yönetimi Üzerine Notlar
Pingback: Exam 70-410: Installing and Configuring Windows Server 2012 (Beta) | Thomas Maurer (tm)
Pingback: Episode 190- Blain Barton and Chad Miller Talk PowerShell and the IT Pro Camps « PowerScripting Podcast
hoi Thomas. Just tried this w. the Win 7 (64) powershell – no go, does not know these commands .. Seems MS vamped up the Win 8 PS w. a bunch of new commands. Do you know if there’s a way to upgrade the Win 7 PS to the level of the one from Win8?
There is a CTP of PowerShell 3.0 for Windows 7, but I am not sure if this will include the Storage or Network cmdlets
Can one also extend the FS on a partition like with Diskpart? That has been the number 1 use I have had for that command when expanding boot volumes or SAN connected volumes to allocate more space.
Yes there is a resize-partition cmdlet
Pingback: Windows Server 2012 Hyper-V – Welcome to the Post-VMware Era! | Thomas Maurer (tm)