Julien De Bona
Free Software, Cooking, and Everything


Create Windows install disks with PowerShell

Publié le 2016-11-30.

As a follow-up to my articles on creating Windows install disks, I wrote a PowerShell module that makes all the operations simple. Short summary in English, it creates a USB disk:

  • containing multiple Windows installers (Windows Vista and newer), possibly with files larger than 4 GB
  • that can boot from BIOS and UEFI
  • without requiring 3rd party tools (only Windows, the install media and this PowerShell module).

It was only tested on Windows 10 (PowerShell 5.0), but it might work on PowerShell 4.0. It will NOT work on a plain Windows 7 as PowerShell 2.0 lacks many cmdlets. Part of the project's objectives were self-teaching and doing as much as possible in native PowerShell.  You can find this module on GitHub.  If it were to be updated, the latest version will be there.

Installation

Download the file at the bottom of this page and copy it to a directory in your %PSMODULEPATH% (I suggest to not mess with the system directories and use the directory in your profile instead). Make sure your execution policy allows you to run this file (that's purely something about PowerShell); you might have to:

  • Configure the execution policy with Set-ExecutionPolicy.
  • Unlock the downloaded module through its properties dialog,.

Available functions

Make sure to run PowerShell as administrator (it needs privileges for partitioning and other tasks).

Get-USBDisk

This lists connected USB disks. If your USB drive is not listed, it means it's not identified itself as a disk, and therefore can't be used (it must be partitioned).  It is simply a wrapper around Get-Disk, for convenience.

Initialize-InstallDisk

This will make a USB disk bootable and install a Windows installer on it. WARNING: This will wipe the disk.

Parameters are:

CDSource
A path to the Windows install media. This can be a directory where the files from an ISO image have been extracted, or to a drive (a real CD or a mounted image on Windows 10); in this case, don't forget to explicitly mention the root directory); default is D:\
Disk
A disk object as returned by Get-USBDisk or Get-Disk
PassThru
If enabled, this switch will make the function return an object representing the installation disk.

Get-InstallDisk

This will return all connected install disks created by Initialize-InstallDisk.

Add-Installer

This adds an installer to an install disk. Parameters are:

CDSource
A path to the Windows install media. (see Initialize-InstallDisk for details)
InstallDisk
An install disk object as returned by Initialize-InstallDisk or Get-InstallDisk
Key
A unique key for the installer; it will be used as name for the directory where the files will be copied on the install disk.
Description
A description for the installer (will be used in the boot menu)

Add-WdsInstaller

This adds a WDS boot image to an install disk. Parameters are:

ImageSource
A path to the boot.wim image (can be retrieved from the network shares on the WDS server)
InstallDisk
An install disk object (see Add-Installer for details)
Key
A unique key for the installer (see Add-Installer for details)
Description
A description for the installer (see Add-InstallDisk for details)
Server
Sets the WDS server containing installation files. If not set, the boot image will use the default WDS server as defined in DNS.

Examples

Initialize a disk and put a second installer (assuming only one USB disk is connected, a Windows 10 install disk is in E: and a Windows Server 2012 R2 is in F:)

$disk = Get-USBDisk
$installDisk = Initialize-InstallDisk -CDSource E:\ -Disk $disk -PassThru
Add-Installer -CDSource F:\ -InstallDisk $installDisk -Key win2012r2 -Description "Windows Server 2012 R2"

Add WDS installers to a previously created install disk (assuming only one install disk is connected). One installer will use the default server, the other one will use the one at wds2.example.org

$installDisk = Get-InstallDisk
Add-WdsInstaller -ImageSource C:\path\to\boot.wim -InstallDisk $installDisk -Key "wds" -Description "WDS installer"
Add-WdsInstaller -ImageSource C:\path\to\boot.wim -InstallDisk $installDisk -Key "wds2" -Description "WDS installer via wds2.example.org" -Server wds2.example.org

Fichiers

  1. 2016-11/InstallDisk

tags: microsoft

Quelques tags ...