Please note that you need to select a disk before you can create a partition.
Read diskpart /?
, use :
Microsoft DiskPart syntax:
diskpart [/s <script>] [/?]
/s <script> - Use a DiskPart script.
/? - Show this help screen.
Note that a DiskPart script is simple plain text file where the diskpart commands are placed in (one command per line), for instance MyDiskpart.txt
listed below.
diskpart /s MyDiskpart.txt
Answer: The latter command you can run from an elevated powershell
session as well as from an elevated cmd
session (˙diskpart˙ always requires elevation).
Addendum:
Moreover, Diskpart
accepts input from a pipe ('|') as well as from <
redirection so that the following cmd
commands are equivalent:
diskpart /s MyDiskpart.txt
diskpart<MyDiskpart.txt
type MyDiskpart.txt|diskpart
The latter commands tested using the following diskpart script:
==> type MyDiskpart.txt
list disk
list volume
select disk 1
list partition
Moreover, you need not to create a diskpart script file; the following .bat
script displays system volume details (selecting volume # dynamically):
@ECHO OFF
SETLOCAL EnableExtensions
:check_permissions
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: Current permissions inadequate.
goto :endlocal
)
:do_the_job
for /f "tokens=2" %%a in ('echo list volume ^| diskpart ^| findstr System') do (
(
echo select volume %%a
echo detail volume
) | diskpart
)
echo DONE
:endlocal
pause