Windows 10: PowerShell Scripting - Update Windows 10 USB install media

Discus and support PowerShell Scripting - Update Windows 10 USB install media in Windows 10 Tutorials to solve the problem; How to: PowerShell Scripting - Update Windows 10 USB install media [img] Information A few weeks after release of Windows 10 version 1703 (Creators... Discussion in 'Windows 10 Tutorials' started by Tony K, Oct 31, 2017.

  1. Tony K Win User

    PowerShell Scripting - Update Windows 10 USB install media


    How to: PowerShell Scripting - Update Windows 10 USB install media

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]
    Information A few weeks after release of Windows 10 version 1703 (Creators Update), Microsoft in April 2017 officially announced that Windows in the future will get biannual feature upgrades:

    Read more: Windows and Office align feature release schedules to benefit customers - Windows Blogs

    Half a year later we got the first of these biannual feature upgrades, current Windows 10 version 1709 Fall Creators Update. Next will be still unnamed version 1803 late March or early April 2018. Until version1803 will be released we will see several cumulative updates, version 1709 has already been updated from build 16299.15 to 16299.19.

    What this means for us Windows users is that when we create install media for a new version, it will be to at least some extent outdated quite some time before the next version is released. This tutorial will show how to keep your USB install media up to date by applying cumulative, critical and security updates to it to assure that Windows 10 when installed from the media is always up to date.

    To start with, create a USB install media for current version of Windows 10. Here on Ten Forums we have several tutorials to show you how:




    Contents [/i]

    [table][tr][td]Part One: Windows Update[/td] [td]Download Windows Update packages[/td] [/tr] [tr][td]Part Two: Run the Script[/td] [td]Apply updates to Windows install media[/td] [/tr] [tr][td]Part Three: What does Script do?[/td] [td]Script explained step by step[/td] [/tr] [/table]


    PowerShell Scripting - Update Windows 10 USB install media [​IMG]
    Note Do parts One & Two to update your Windows 10 install media. Part Three is optional, for those interested in how the script was built. It is not required for the USB update process.



    Part One: Windows Update [/i] Download Windows Update packages 1.1) Go to Microsoft Update Catalog: https://www.catalog.update.microsoft.com/

    1.2) Search updates for Windows 10 version of your install media you want to update. I have created a USB install media for unattended hands-free install of Windows 10 version 1709 (tutorial), I will search updates for version 1709:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    (Click screenshots to enlarge.)

    Search found a cumulative update and a security update for Flash Player for both 64 bit systems (highlighted blue) and 32 bit systems (yellow), and cumulative update for systems with ARM64 processor (green). Some device specific updates for Windows 10 S version 1709 were also found (red), I'm not interest in them because I do not have Windows 10 S installed nor do I have install media for it

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]
    Note Sometimes, depending on Windows version and how long since it was released, Update Catalog finds more than one cumulative update. In this case it is enough to download the most recent cumulative update and all critical updates and security updates released after it.
    1.3) In my case, wanting to update 64 bit install media, I will download both x64 updates:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    PowerShell Scripting - Update Windows 10 USB install media [​IMG]
    Note Be sure to download Windows Updates for correct bit version, x64 if you will update a 64 bit Windows install media and x86 if updating 32 bit install media.
    1.4) I saved the updates in folder H:\WindowsUpdate which I created specifically to store Windows Update files:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]





    Part Two: Run the Script [/i] Apply updates to Windows install media 2.1) Plug in your Windows 10 install USB flash drive. Check that install.wim file in Sources folder is not write protected (Read Only) in file properties. If Read Only is selected, unselect it to disable write protection.

    2.2) Download USBUpdate.ps1 script from OneDrive, save it to local PC selecting Save or Save As. Do not select Open or Run:

    Download

    2.3) Right click downloaded file, select Properties:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    2.4) Select Unblock (tick the box), click OK:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    2.5) Open Settings app, select Update & Security, select For developers, click Apply under PowerShell to allow local unblocked scripts to be run:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    PowerShell Scripting - Update Windows 10 USB install media [​IMG]
    Note The Apply button will be greyed out if this setting is already applied:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]

    2.6) Run USBUpdate.ps1 script by right clicking it and selecting Run with PowerShell:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    You can of course run script if you so prefer manually from PowerShell or from PowerShell ISE using both normal user mode or elevated PowerShell, script will be automatically elevated if started from user mode.

    To run script from PS, enter following command, replacing path X:\Scripts with actual path to folder where script is stored:

    & "X:\Scripts\USBUpdate.ps1"

    If script is in current PS working folder, use following command:

    .\"USBUpdate.ps1"

    2.7) Depending on your current execution policy level (read more) you might get a notification as shown in screenshot. Press Y and Enter to accept:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    If you will get an error message in red telling running scripts is disabled, you've forgot either step 2.4 or step 2.5:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    2.8) Script will be run:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    2.9 ) If script was started with right click > Run in PowerShell, or if it was started manually from a normal user mode PS, a new elevated "Run as administrator" PS process will be started.

    In this case, depending on your UAC settings, you will be asked to allow PS to be elevated. Click Yes:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    2.10) Follow on-screen instructions to update Windows install media, a USB flash drive or an ISO image




    Part Three: What does script do? [/i] Script explained step by step 3.1) OK, let's go shortly through the modules in this script. In this part we'll look at each screen user will see and the code for it.

    I have used a lot of remarks to make script more readable. Lines starting with a hash sign are ignored when script is run and can be used for remarks and notes.

    Here's the script to start with, all almost 400 lines of it, including remarks and empty lines to separate modules:

    Code:
    3.2) In my opinion one of the characteristics of good code, be it a batch file or script or an application is clear and precise on-screen instructions to end user. I recommend both adding enough remarks for those reading the source code, and really doing your best to make output clear, understandable and readable.

    To increase readability I add a leading space to any text output line because PS has this annoying non-existing left margin. Two screenshots to show what I mean:

    With a leading space in every line of output:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Without leading space:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Notice that command PAUSE which I use to give user time to read instructions will automatically output text string Press Enter to continue... which will by default have no leading space. To add one, I'll write a line only containing a single space with -NoNewline switch at the end of the command line which tells PS not to start new line after string (single space in this case) has been written (highlighted in code extract):

    Code:
    Now the next line, command PAUSE will not write its output to a new line without leading space but will instead continue on previous line after that single space.

    Also notice in above code extract how warning about ESD file is shown using other colors, inverting them with -ForegroundColor DarkBluesetting the text color to blue and -BackgroundColor White as the name says setting the background color to white. To make it look better, character count (including spaces) in each line is the same to show white background exactly as long in each line.

    Opening screen looks like this:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.3) Already before showing opening screen, we have checked if script has been started elevated and if not, we will start a new elevated PS process.

    Beauty of modular structure of a PS script is in how easy it is to reuse parts of it, even borrow code from other geeks. In this case I use a function by Matt Painter I found on TechNet Script Center:

    Code:
    Microsoft TechNet Script Center: Powershell, VB Script, SQL and JavaScript - TechNet IT Pros and Scripting Guys
    "Use-RunAs" function: Re-launch Powershell Script Elevated

    3.4) After opening screen we will check if old log files from previous runs of this script exist, if yes we will remove them, then ask user path to source which can be either a USB drive or a folder where ISO content has been copied:

    Code:
    What user will see:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Alternatively, if source path does not contain valid Windows image:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Or, if given source path does not exist:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]



    3.5) Next step is to check install.wim, show user which editions it contains and ask which edition should be updated:

    Code:
    What user will see:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.6) Time to prompt user for path to folder containing downloaded Windows update .msu and / or .cab files:

    Code:
    User will see this:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Again, we are prepared for two possible errors:

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.7) To mount a Windows image we need some space. A compressed image (install.wim) is under 4 GB but needs over triple that space when mounted. Mounting a standard v. 1709 W10 PRO install.wim takes over 12 GB

    We will now check all hard disk partitions and list them to user showing how much free space each of them has available and let user to pick drive where temporary mount folder will be created:

    Code:
    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.8) That's it, we have collected all required information. Script starts working.

    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    Image will be mounted:
    Code:
    3.9) Updates will be written (applied) to image:

    Code:
    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.10) Dismounting the image, saving changes to install.wim (applied updates):

    Code:
    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    3.11) Show user which updates were applied, delete temporary mount folder, show end credits:
    Code:
    PowerShell Scripting - Update Windows 10 USB install media [​IMG]


    That's it this time!

    Kari


    Related Tutorials

    :)
     
    Tony K, Oct 31, 2017
    #1
  2. saberman Win User
    saberman, Oct 31, 2017
    #2
  3. URGENT!!! Please update the Windows Update troubleshooter scripts!

    I call upon the Windows Team to plead them to update the Windows Update Troubleshooter script on Windows 10, because the tool that comes with the system dates back to 2012 (I found the PowerShell scripts, and some even include Windows XP stuff and some
    were really old PowerShell 1.0 scripts) and didn't solve my 0x80200001 and 0x8024000b WindowsUpdateFailure3 errors.

    After a month of horrible suffering, damaging several W10 installations beyond repair, wiping and swapping disks, posting several topics here at the community and other places, I finally found a script that appears to solve my issues. http://go.microsoft.com/?linkid=9830262

    This is a diagcab from Microsoft (it's for Windows 8.1, but it worked flawlessly on Windows 10)

    Please!! spread the word, for those who are suffering the same fate as I, let the engineers know that they forgot to update these Troubleshooter scripts!
     
    Cesar Morgan Recinos, Oct 31, 2017
    #3
  4. Kari Win User

    PowerShell Scripting - Update Windows 10 USB install media

    Thanks Tony.

    Especially if you clean install every now and then or have multiple machines to install, it's quite practical to keep install media up to date, not having to run Windows Update every time on newly installed Windows. When those updates have been "injected" to install media, your clean install is up to date as soon as it enters desktop.
     
Thema:

PowerShell Scripting - Update Windows 10 USB install media

Loading...
  1. PowerShell Scripting - Update Windows 10 USB install media - Similar Threads - PowerShell Scripting Update

  2. Pause windows update with a powershell script

    in Windows 10 Gaming
    Pause windows update with a powershell script: Hi,I am trying to remotley pause windows update using a powershell script.I have tried installing PSWindowsUpdate module on the remote PC and then running: Set-WindowsUpdateAutoUpdateOption -AutoUpdateOption 2This didnt work and i am getting that...
  3. Pause windows update with a powershell script

    in Windows 10 Software and Apps
    Pause windows update with a powershell script: Hi,I am trying to remotley pause windows update using a powershell script.I have tried installing PSWindowsUpdate module on the remote PC and then running: Set-WindowsUpdateAutoUpdateOption -AutoUpdateOption 2This didnt work and i am getting that...
  4. PowerShell script to disable/enable usb storage in windows

    in Windows 10 Gaming
    PowerShell script to disable/enable usb storage in windows: Hello,can someone please help me with a PowerShell script, which will disable usb storage.requirements:1 everything should be done through PowerShell script2 already installed usb should not be accessible 3 not ready to install any 3rd party application4 Restarting pc is not...
  5. PowerShell script to disable/enable usb storage in windows

    in Windows 10 Software and Apps
    PowerShell script to disable/enable usb storage in windows: Hello,can someone please help me with a PowerShell script, which will disable usb storage.requirements:1 everything should be done through PowerShell script2 already installed usb should not be accessible 3 not ready to install any 3rd party application4 Restarting pc is not...
  6. PowerShell script to disable/enable usb storage in windows

    in Windows 10 Drivers and Hardware
    PowerShell script to disable/enable usb storage in windows: Hello,can someone please help me with a PowerShell script, which will disable usb storage.requirements:1 everything should be done through PowerShell script2 already installed usb should not be accessible 3 not ready to install any 3rd party application4 Restarting pc is not...
  7. PowerShell script

    in Windows 10 Support
    PowerShell script: The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file. 19.191.12.161 - online 19.191.12.162 - offline 19.191.12.163 - offline 19.191.12.164 - offline 19.191.12.165 - offline also see the scrennshot Code: $Output= @()$GetIP =...
  8. powershell scripts

    in AntiVirus, Firewalls and System Security
    powershell scripts: Hi, I have azure. Someone is somehow installing powershell scripts onto my computer that allows them to host my PC through P2P and UDP connections, well I think so anyway. I have only just found powershell script entry changes in my registry by accident. These criminals...
  9. powershell script

    in Windows 10 Customization
    powershell script: looking for a script to monitor for a folder, if there is a file in that folder send it as an email, once the email is sent out, confirm and then move the files to an archive folder. monitor c:\test\*.pdf No files, do not send email. Yes Files, send an email to someone at...
  10. PowerShell Scripting - Create USB Install Media for Windows 10

    in Windows 10 Tutorials
    PowerShell Scripting - Create USB Install Media for Windows 10: How to: PowerShell Scripting - Create USB Install Media for Windows 10 [img] Information The way Windows operating system is delivered and installed has changed quite a lot from days when Windows 3.0 was delivered on 6 floppy disks. To install, you booted PC from floppy...

Users found this page by searching for:

  1. power shell script for store windows 10 ltsc