Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HOW TO AUTOMATE DISKPART?
#1
Question 
I am trying to find a way of automating Diskpart to just make a USB stick Bootable!
I have the means and knowledge to add an ISO file later.

I thought I could create a Batch File to do the job for me in Windows 10 (using latest version).

At a DOS/Command Prompt, the batch file needs to enter DISKPART and then the following commands, once a USB has been inserted into my desktop PC:-

Diskpart>

list disk
select disk
clean
create part pri
select part 1
active
assign
format fs=FAT32 quick
exit

At certain points, manual input would be required from the user, far easier than having to key in all the above commands.

I understand that "Scripts" may help but I do not know how to create or use them.

Any help would be much appreciated!!!
Kind regards
Mike
Reply

#2
Here is one way of doing it:

Note: Replace X: below with the path where you kept both files

Code:
@echo off
DISKPART /s X:\BootableUSB.txt
xcopy H:\*.* /s/e/f M:\
pause
exit

Copy and paste the text below and save as BootableUSB.txt

Code:
SELECT DISK 1
CLEAN
CREATE PARTITION PRIMARY
SELECT PARTITION 1
ACTIVE
FORMAT QUICK
ASSIGN LETTER=M
EXIT

Make sure files are kept in same location and then run the batch file from a elevated command prompt.


Here are some other ways:

https://maxyspark.com/2016/05/09/make-bootable-usb-with-your-own-softwarescript/


https://mithunmanoharan.blogspot.co.uk/2016/04/making-bootable-pendrive-bat-file.html
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#3
Thanks for your fast reply.
Unfortunately none of these solutions work. They leave errors too numerous to mention.
I had seen two of the solutions before so I will make another search of the internet.
Once again, thanks for your reply!

Regards,
Mike
Reply

#4
Since Brian made a Tutorial at the beginning of this month about How to Automate Diskpart, the solutions he gave me using Batch Files did not work for me.
However, I have made an attempt to write a small script, using Windows Powershell, which does work but obviously needs work doing to it!

The first USB which I plug into my desktop PC is always "DriveLetter I", and is the 6th disk on the "List Disk" output list, select "DiskNumber 5".
I have placed a "Pause" in the script to allow the list of disks to be read, please see attachment showing the screen output in blue and the script, as follows:-

  [attachment=3499]

This script formats the USB in FAT32, I have another .ps1 file formatting in NTFS
This Powershell language is not like Batch files and I can't find any menu options to try to merge the two scripts and create variables for DriveLetter, DiskNumber and Format (FAT32 or NTFS) and Disk Label.

Just thought you may be able to help in creating a script which will do everything!!!
Reply

#5

If you would like user interaction in the batch files, there's a nice article at https://www.robvanderwoude.com/userinput.php#NT; you may want to check that

With respect to starting the batch file whenever a USB drive is plugged in, you may refer to the article at https://tinyurl.com/ycg4a3p9
Reply

#6
(03-23-2018, 10:35 PM)Partha Wrote:  
If you would like user interaction in the batch files, there's a nice article at https://www.robvanderwoude.com/userinput.php#NT; you may want to check that

With respect to starting the batch file whenever a USB drive is plugged in, you may refer to the article at https://tinyurl.com/ycg4a3p9

Hello Partha,
Thanks for your reply yesterday....not exactly what I was looking for though.
[attachment=3501]

I merely want to automate the Diskpart process when I have difficulty with a USB stick, particularly when it is not recognised.

Batch files will not do it on my PC, so I have moved on to Windows Powershell, a completely different animal.
The attachment shows the coding, basically I want to merge two small scripts, one formatting in FAT32 and the other in NTFS.

I am really looking for a Powershell solution where I can Input certain information, such as choosing the correct DiskNumber to format, either in FAT32 or NTFS, choose the DriveLetter, DriveLABEL.

But again, thanks for responding!!

Regards,
Mike
Reply

#7
I did a video for you a while back





This one is a powershell way



<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply

#8
Hello Brian
Thank you so much for posting another Youtube Video.
The Powershell one is now working.
I have left a small donation, but don't go wild, it's only a fiver!!!!

Thanks once again,
Kind regards
Mike-m5
Reply

#9
Thanks Mike
<left><form action="https://www.paypal.com/cgi-bin/webscr" method="post">If you are satisfied with my help, consider a donation. Thank you so much for your continued support! 
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="Y4ZDLXGFS4F8Q">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="0" height="0">
</form>

   </div></left> 
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 Melroy van den Berg.