Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > DISKPART select command doesn't have a "noerr" command for scripti

Reply
Thread Tools Display Modes

DISKPART select command doesn't have a "noerr" command for scripti

 
 
WB
Guest
Posts: n/a

 
      11-25-2008
I'm trying to programmatically delete all partitions from a drive, however
I'm not sure how many partitions the drive has.

I thought the script below would work, but if any of the partitions don't
exist, the script stops execution when trying to select them. This is because
there is not a "noerr" parameter for selecting the partitions.

I don't understand what good the "noerr" parameters are when you have to
select items first, and the select function has no "noerr" parameter so it
fails???:

BTW: I cannot use "clean" (please don't ask why)

select disk 0
select partition 1
delete partition noerr
select partition 2
delete partition noerr
select partition 3
delete partition noerr
select partition 4
delete partition noerr
select partition 0
delete partition noerr
select disk 0
create partition primary size 2000
format FS=FAT LABEL="PARTITION1" QUICK
assign letter d
create partition extended
create partition logical
format FS=NTFS LABEL="PARTITION2" QUICK
assign letter c
Active
Exit

Thanks,
--
Bill Baker
 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      11-25-2008

"WB" <> wrote in message
news3618F52-6C8F-4239-A240-...
> I'm trying to programmatically delete all partitions from a drive, however
> I'm not sure how many partitions the drive has.
>
> I thought the script below would work, but if any of the partitions don't
> exist, the script stops execution when trying to select them. This is
> because
> there is not a "noerr" parameter for selecting the partitions.
>
> I don't understand what good the "noerr" parameters are when you have to
> select items first, and the select function has no "noerr" parameter so it
> fails???:
>
> BTW: I cannot use "clean" (please don't ask why)
>
> select disk 0
> select partition 1
> delete partition noerr
> select partition 2
> delete partition noerr
> select partition 3
> delete partition noerr
> select partition 4
> delete partition noerr
> select partition 0
> delete partition noerr
> select disk 0
> create partition primary size 2000
> format FS=FAT LABEL="PARTITION1" QUICK
> assign letter d
> create partition extended
> create partition logical
> format FS=NTFS LABEL="PARTITION2" QUICK
> assign letter c
> Active
> Exit
>
> Thanks,
> --
> Bill Baker


I don't know anything about diskpart.exe but you could walk around the
problem by using this batch file to automate the job.

@echo off
echo> diskpart1.scr select disk 0
echo>>diskpart1.scr list partition
echo>>diskpart1.scr exit
diskpart < diskpart1.scr | findstr /i "primary logical" > diskpart.txt

echo>diskpart2.scr select disk 0 > diskpart2.scr
for /F "tokens=1,2" %%a in (diskpart.txt) do (
echo>>diskpart2.scr %%a %%b
echo>>diskpart2.scr delete partition noerr
)

echo>>diskpart2.scr select disk 0
echo>>diskpart2.scr create partition primary size 2000
echo>>diskpart2.scr format FS=FAT LABEL="PARTITION1" QUICK
echo>>diskpart2.scr assign letter d
echo>>diskpart2.scr create partition extended
echo>>diskpart2.scr create partition logical
echo>>diskpart2.scr format FS=NTFS LABEL="PARTITION2" QUICK
echo>>diskpart2.scr assign letter c
echo>>diskpart2.scr Active
echo>>diskpart2.scr Exit

diskpart < diskpart2.scr


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Mail Command "The Command Failed To Execute" southron_98 Windows Vista Mail 29 07-26-2009 11:34 PM
"Open command prompt here" and "Copy as path" Moody Marco Windows Vista Performance 10 05-04-2007 04:41 PM
RE: SMTP command "xexch50" with "504 Need to authenticate first ". The full command sent was "XEXCH50 1020 2 ". Steven Zhu [MSFT] Windows Small Business Server 1 12-08-2006 06:54 AM
[PS] Difference between "get-command" and "get-command *" Andrew Watt [MVP] Scripting 3 05-16-2006 08:10 AM
export subnets from "Sites and Services" using command line tools thomas Active Directory 3 01-26-2005 12:09 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59