By using this site, you agree to the Privacy Policy.
Accept
EnterinITEnterinITEnterinIT
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Reading: PowerShell Disks and Partitions Management
Font ResizerAa
EnterinITEnterinIT
Font ResizerAa
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
  • WINDOWS
  • SCCM Query Collection List
Search
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
IT Pro

PowerShell Disks and Partitions Management

Published February 18, 2024
3 Min Read
SHARE

PowerShell Disks and Partitions Management. There are about 166 (Windows 1903) PowerShell cmdlets in the Storage module in Windows 10. To display all available commands related to disk management.

Contents
List Local Disks and PartitionsDisk Initialization in PowerShellHow to Create Partitions on a Disk?Formatting a partition with PowerShellHow to Remove Partitions from a Disk?
Get-Command -Module Storage

List Local Disks and Partitions

Display the list of local disks available in your system at the logical level.

Get-Disk | ft -AutoSize

Select only the system disk on which Windows is installed.

Get-Disk | Where-Object IsSystem -eq $True | fl

You can display Offline disks only.

Get-Disk | Where-Object IsOffline –Eq $True| ft –AutoSize

If you need information about physical disks (the characteristics and status of physical disks on a computer), use Get-PhysicalDisk.

You can display the list of partitions on all disks.

Get-Partition

Or partitions on the specified disks only.

Get-Partition –DiskNumber 1,2

Disk Initialization in PowerShell

1. Get the disk Online;

Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False

2. Initialize it;

Initialize-Disk -Number 1

By default, a GPT (GUID) partition table is created on a disk, but if you need an MBR one.

Initialize-Disk 1 –PartitionStyle MBR

NOTE: If there are some data on the disk, you can change the partition table from MBR to GPT without removing the data using the mbr2gpt.exe tool.

How to Create Partitions on a Disk?

To create a new partition on a disk, the New-Partition cmdlet is used.

New-Partition –DiskNumber 1 -Size 100gb -DriveLetter G

If you want the partition to occupy all available disk space, use the UseMaximumSize attribute. To assign a letter automatically, the AssignDriveLetter parameter is used.

New-Partition –DiskNumber 1 -AssignDriveLetter –UseMaximumSize

You can change the assigned letter.

Set-Partition –DriveLetter L -NewDriveLetter U

If you want to make a partition active.

Set-Partition -DriveLetter U -IsActive $true

Formatting a partition with PowerShell

Format the new partition in the NTFS and set the Data volume label.

Format-Volume -DriveLetter G -FileSystem NTFS -NewFileSystemLabel Data -Confirm:$false

How to Remove Partitions from a Disk?

Remove all partitions on disks 1 and 2 without confirmation.

Get-Partition –DiskNumber 1,2 | Remove-Partition -Confirm:$false

To delete all partitions from disks and completely clear data.

Clear-Disk -Number 1 -RemoveData -Confirm:$false
TAGGED:Microsoft Windows ServerPowerShellWindowsWindows 10
Previous Article Office Insider 1910 for Windows
Next Article Azure AD Connect Error stopped-deletion-threshold-exceeded
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translation

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
by Transposh - translation plugin for wordpress

Popular Posts

System Requirements for Windows Server 2016
Windows Server
Configuration Manager Query Collection List
Configuration Manager Query Collection List
ConfigMgr
Structured/Managed Navigation enabled on Modern Pages in Classic Team Sites
Tech
SCCM Failed to get DP locations as the expected version from MP
ConfigMgr

Recent Posts

Installing and Configuring Fail2ban for SSH Protection on Ubuntu 24.04
Linux
Enabling and Configuring FirewallD on AlmaLinux
Linux
User Creation and SSH Key Setup in AlmaLinux
Linux
How to reset password on AlmaLinux
Linux

© 2023 EnterinIT

Go to mobile version
adbanner
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?