Skip to content

h4rithd/RefusePS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

RefusePS

RefusePS is a PowerShell-based Windows bootable USB creator. It prepares a USB drive, formats it as FAT32, mounts a Windows ISO, copies the installer files, and automatically splits install.wim when required for FAT32 compatibility.


Features

  • Safely lists available USB disks before wiping
  • Requires manual disk selection
  • Requires explicit ERASE confirmation before destructive actions
  • Creates a GPT/FAT32 USB installer for UEFI systems
  • Mounts Windows ISO automatically
  • Copies Windows setup files using robocopy
  • Splits large install.wim files into .swm files using DISM
  • Supports ISOs containing either:
    • sources/install.wim
    • sources/install.esd
  • Dismounts ISO after completion
  • Attempts to eject USB after completion

Warning

This script will erase the selected USB disk. Use it carefully.

Before running RefusePS:

  • Remove USB drives you do not want to wipe
  • Double-check the disk number
  • Make sure the ISO path is correct
  • Run PowerShell as Administrator

The author is not responsible for data loss caused by selecting the wrong disk.


Requirements

  • Windows 10 or Windows 11
  • PowerShell 5.1 or newer
  • Administrator privileges
  • A Windows ISO file
  • A USB drive, preferably 8 GB or larger
  • UEFI-capable target system

Usage

Clone the repository:

git clone https://github.com/YOUR_USERNAME/RefusePS.git
cd RefusePS

Edit the ISO path inside RefusePS.ps1:

$isoImage = "C:\Path\To\windows10.iso"

Run PowerShell as Administrator.

Then execute:

.\RefusePS.ps1

The script will show detected USB disks:

Number FriendlyName        SerialNumber Size PartitionStyle
------ ------------        ------------ ---- --------------
1      SanDisk USB Drive   XXXXXXXX     16GB MBR

Enter the correct USB disk number.

To confirm wiping the disk, type:

ERASE

RefusePS will then create the bootable USB installer.


Why FAT32?

FAT32 is used because it is widely supported by UEFI firmware. However, FAT32 has a single-file size limit of 4 GB. Many Windows ISO files include an install.wim file larger than 4 GB. RefusePS handles this by splitting install.wim into smaller .swm files:

install.swm
install2.swm
install3.swm

Windows Setup supports this split-image format.


GPT vs MBR

RefusePS uses GPT partitioning by default. This is suitable for modern UEFI-based systems. If you need Legacy BIOS boot support, GPT/FAT32 may not be enough. In that case, you may need to modify the script to use MBR instead.


Script Overview

RefusePS performs the following actions:

  1. Checks that the ISO exists
  2. Lists detected USB disks
  3. Asks the user to select the target USB disk
  4. Requires confirmation before wiping
  5. Clears the selected USB disk
  6. Initializes it as GPT
  7. Creates a FAT32 partition
  8. Mounts the Windows ISO
  9. Copies ISO contents to the USB drive
  10. Excludes install.wim and install.esd during the first copy
  11. Splits install.wim if found
  12. Copies install.esd if found and under 4 GB
  13. Dismounts the ISO
  14. Attempts to eject the USB drive

Safety Notes

RefusePS avoids wiping every USB disk automatically. Unlike unsafe one-liners such as:

Get-Disk | Where BusType -eq 'USB' | Clear-Disk

RefusePS forces the user to select one USB disk and confirm the operation.

Still, the script is destructive. If you choose the wrong disk, the data will be erased.


Troubleshooting

PowerShell blocks the script

Run:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Then run:

.\RefusePS.ps1

This only changes the execution policy for the current PowerShell session.


Robocopy failed

Robocopy exit codes below 8 usually mean success or partial success.

RefusePS treats exit codes 8 and above as failure.

Check that:

  • The ISO is mounted correctly
  • The USB drive is writable
  • The USB drive has enough space

DISM failed while splitting install.wim

Make sure you are running PowerShell as Administrator.

Also verify that the Windows ISO is not corrupted.


USB does not boot

Check the following:

  • Target machine supports UEFI boot
  • Secure Boot settings are compatible with the ISO
  • USB boot is enabled in firmware settings
  • The USB drive is selected from the boot menu
  • The ISO is a valid Windows installation ISO

Disclaimer

RefusePS is provided as-is.

You are responsible for verifying the selected disk before continuing.

Always back up important data before using disk formatting or disk wiping tools.


Author

Harith Dilshan (h4rithd.com)

About

RefusePS is a PowerShell tool for creating bootable Windows USB installers from ISO files, with safe USB selection, FAT32 formatting, and automatic install.wim splitting.

Topics

Resources

Stars

Watchers

Forks

Contributors