Insights Technical Hub How to write scripts for disk management with diskpart

How to write scripts for disk management with diskpart

Introduction:

Disk management in Windows is possible from the command line, especially with tools such as diskpart. Diskpart can be scripted for quicker disk management.

Requirements:

Access to the Windows command line and a file editor.

Procedure:

Open a file editor and enter diskpart commands such as:

list disk
select disk 1
offline disk

The above will simply offline the second disk recognized by diskpart. This disk can be onlined at another time.

Next, you can save this file with a .txt file extension. With the command line open, you can run this script by typing:

diskpart /s C:\Users\User\Folder\filename.txt

and the disk will then be offlined.

More Information:

For a list of diskpart commands, type:

help

within a diskpart session.