- Sample scripts
- Image deployment scripts
- ApplyImage.bat
- CreatePartitions scripts
- CreatePartitions-UEFI.txt
- CreatePartitions-UEFI-FFU.txt
- CreatePartitions-BIOS.txt
- CreatePartitions-BIOS-FFU.txt
- ApplyRecovery.bat
- CreateRecoveryPartitions-UEFI.txt
- CreateRecoveryPartitions-BIOS.txt
- HideRecoveryPartitions-UEFI.txt
- HideRecoveryPartitions-BIOS.txt
- Start layout (LayoutModification.xml)
- TaskbarLayoutModification.xml
- BootToAudit
- BootToAudit-x64
- Keeping Windows settings through a recovery
- ResetConfig.xml
- EnableCustomizations.cmd
- Reinstall Windows inbox apps
- ReinstallInboxApps-x64.cmd
- Find drive letters with a script
- Windows Installer Scripting Examples
- How to create and run a PowerShell script file on Windows 10
- How to create PowerShell script file on Windows 10
- Creating script with Visual Studio Code
- Install Visual Studio Code
- Install PowerShell extension
- Create PowerShell script with Visual Studio Code
- Creating script with Notepad
- Creating script with Integrated Scripting Environment
- How to run PowerShell script file on Windows 10
- More Windows 10 resources
- Halo: MCC’s live service elements make it better, not worse
- Microsoft’s Surface Duo is not ‘failing up’
- Here’s what you can do if Windows 10 update KB5001330 is causing issues
- These are the best PC sticks when you’re on the move
Sample scripts
Copy these scripts to the root of your storage USB drive. Refer to this page to understand what’s in the scripts.
The sample scripts ZIP download includes all the scripts below:
Image deployment scripts
The following scripts set up Windows devices by using either a WIM or an FFU image file, and then give the option to configure push-button reset features.
The following files make up the deployment scripts:
- ApplyImage.bat
- ApplyRecovery.bat
- CreatePartitions-BIOS.txt
- CreatePartitions-BIOS-FFU.txt
- CreatePartitions-UEFI.txt
- CreatePartitions-UEFI-FFU.txt
- HideRecoveryPartitions-BIOS.txt
- HideRecoveryPartitions-UEFI.txt
- CreateRecoveryPartitions-BIOS.txt
- CreateRecoveryPartitions-UEFI.txt
ApplyImage.bat
Use this script applies a Windows image to a new device.
Note: If you copy and paste the contents below to create a .bat file, you may get an error when detecting firmware. For firmware detection to succeed, ensure that the lines that begin for /f «tokens=2* delims= » %%A has a tab followed by a space in between delims= and » %%A .
ApplyImage.bat relies on the following DiskPart scripts, which must be placed in the same folder:
CreatePartitions scripts
Use these scripts together with DiskPart to format and set up the hard disk partitions for Windows, including recovery tools. Adjust the partition sizes to fill the drive as necessary.
CreatePartitions-UEFI.txt
Creates the System, MSR, Windows, and recovery tools partitions for UEFI-based PCs.
This script temporarily assigns these drive letters: System=S, Windows=W, and Recovery=R. The MSR partition doesn’t get a letter. The letter W is used to avoid potential drive letter conflicts. After the device reboots, the Windows partition is assigned the letter C, and the other partitions don’t receive drive letters.
The Recovery partition must be the partition after the Windows partition to ensure winre.wim can be kept up-to-date during life of the device.
The following diagram shows the resulting partition configuration:
CreatePartitions-UEFI-FFU.txt
This script is based off of CreatePartitions-UEFI.txt, but it does not create a recovery partition. This is so that the Windows partition is the last partition on the drive and can be expanded. If this script is used, the recovery partition can be configured later with ApplyRecovery.bat.
CreatePartitions-BIOS.txt
Creates the System, Windows, and recovery tools partitions for BIOS-based PCs.
This script temporarily assigns these drive letters: System=S, Windows=W, and Recovery=R. The letter W is used to avoid potential drive letter conflicts. After the device reboots, the Windows partition is assigned the letter C, and the other partitions don’t receive drive letters.
The Recovery partition must be the partition after the Windows partition to ensure winre.wim can be kept up-to-date during life of the device.
The following diagram shows the resulting partition configuration:
CreatePartitions-BIOS-FFU.txt
This script is based off of CreatePartitions-BIOS.txt, but it doesn’t create a recovery partition. This is so that the Windows partition is the last partition on the drive and can be expanded. If this script is used, the recovery partition can be configured later with ApplyRecovery.bat.
ApplyRecovery.bat
Use this script to prepare the Windows recovery partition. This script is called by ApplyImage.bat, but can also be run on its own.
Note: If you copy and paste the contents below to create a .bat file, you may get an error when detecting firmware. For firmware detection to succeed, ensure that the lines that begin for /f «tokens=2* delims= » %%A has a tab followed by a space in between delims= and » %%A .
ApplyRecovery.bat relies on the following DiskPart scripts, which must be placed in the same folder:
CreateRecoveryPartitions-UEFI.txt
CreateRecoveryPartitions-BIOS.txt
HideRecoveryPartitions-UEFI.txt
HideRecoveryPartitions-BIOS.txt
Start layout (LayoutModification.xml)
The Start tile layout in Windows 10 provides OEMs the ability to append tiles to the default Start layout to include Web links, secondary tiles, Windows apps, and Windows desktop applications. OEMs can use this layout to make it applicable to multiple regions or markets without duplicating a lot of the work. In addition, OEMs can add up to three default apps to the frequently used apps section in the system area, which delivers sytem-driven lists o the user including important or frequently accessed system locations and recently installed apps.
To take advantage of all these new features and have the most robust and complete Start customization experience for Windows 10, consider creating a LayoutModification.xml file. This file specifies how the OEM tiles should be laid out in Start. For more information about how to customize the new Start layout, see the topic Customize the Windows 10 Start screen in the Windows 10 Partner Documentation.
Sample LayoutModification.xml:
TaskbarLayoutModification.xml
You can pin apps to the taskbar. To learn more, see OEM Taskbar tiles.
BootToAudit
Add an answer file to the Windows image in C:\mount\windows\Windows\Panther\unattend.xml to instruct it to boot into audit mode. You can create this answer file in Windows System Image Manager.
BootToAudit-x64
Keeping Windows settings through a recovery
Windows doesn’t automatically save settings created through unattend.xml setup files, nor Windows Start Menu customizations created with LayoutModification.xml during a full-system reset, nor first-login info from oobe.xml.
To make sure your customizations are saved, that includes steps to put the unattend.xml, LayoutModification.xml, and oobe.xml files back into place. Here’s some sample scripts that show how to retain these settings and put them back into the right spots. Save copies of unattend.xml, LayoutModification.xml, oobe.xml, plus these two text files: ResetConfig.xml and EnableCustomizations.cmd, in C:\Recovery\OEM\:
ResetConfig.xml
EnableCustomizations.cmd
To learn more about using extensibility points for push-button reset, see Add extensibility scripts to push-button reset.
Reinstall Windows inbox apps
Reinstall Windows apps after adding a new language. You can reinstall the apps without removing them first.
ReinstallInboxApps-x64.cmd
Find drive letters with a script
Use this script in Windows PE to identify a drive that has a folder called «Images.»
Windows Installer Scripting Examples
The Windows SDK Components for Windows Installer Developers contains VBScript files that show you how the Windows Installer automation interface is used to modify Windows Installer packages.
The script samples identified in this topic are not supported by Microsoft Corporation, and they are provided only as a potentially useful reference. Running these samples requires the Windows Script Host. For more information about Windows Script Host, see the Windows Script Host section of the Microsoft Windows Software Development Kit (SDK).
Sample Script File | Description |
---|---|
WiLstPrd.vbs | List Products, Properties, Features, and Components |
WiImport.vbs | Import Files |
WiExport.vbs | Export Files |
WiSubStg.vbs | Manage Substorages |
WiStream.vbs | Manage Binary Streams |
WiMerge.vbs | Merge Two Databases |
WiGenXfm.vbs | Generate a Transform |
WiUseXfm.vbs | Apply a Transform |
WiLstXfm.vbs | View a Transform (CSCRIPT only) |
WiDiffDb.vbs | View Differences Between Two Databases (CSCRIPT only) |
WiLstScr.vbs | View Installer Script (CSCRIPT only) |
WiSumInf.vbs | Manage Summary Information |
WiPolicy.vbs | Manage Policy Settings |
WiLangId.vbs | Manage Language and Codepage |
WiToAnsi.vbs | Copy a Unicode File to an Ansi File |
WiFilVer.vbs | Manage File Sizes and Versions |
WiMakCab.vbs | Generate File Cabinet |
WiRunSQL.vbs | Execute SQL Statements |
WiTextIn.vbs | Copy ANSI File Into a Database Field |
WiCompon.vbs | List Components |
WiFeatur.vbs | List Features |
WiDialog.vbs | Preview User Interface |
All these scripts display a help screen that describes their command line arguments. To display the help screen in Windows double-click the file. To display the help screen from a command line enter a ? as the first argument, or enter fewer arguments than required. Scripts return a value of 0 for success, 1 if help is invoked, and 2 if in case of failure.
These samples require Windows Script Host to run. Windows Script Host is actually two hosts:
How to create and run a PowerShell script file on Windows 10
Source: Windows Central
On Windows 10, PowerShell is a command-line tool designed by Microsoft to run commands and scripts to change settings and automate tasks. In a way, it’s similar to Command Prompt. However, PowerShell is a more capable command-line interface (CLI) that offers an extensive set of tools and more flexibility and control. Also, unlike Command Prompt, PowerShell is available on Windows, macOS, and Linux.
A script is just a collection of commands saved into a text file (using the special «.ps1» extension) that PowerShell understands and executes in sequence to perform different actions.
The only caveat is that the default security protocol always blocks any script from running on a device. This means that when double-clicking a «.ps1» file on Windows 10 nothing will happen, and if you try to run the script within PowerShell, you’ll see the «cannot be loaded because running scripts is disabled on this system» error message. However, it’s not impossible to run scripts on your computer. You only need to enable the correct execution policy.
In this Windows 10 guide, we’ll walk you through the steps to successfully write and run your first script file on PowerShell using Visual Studio Code, Notepad, and the PowerShell Integrated Scripting Environment (ISE) console.
How to create PowerShell script file on Windows 10
On Windows 10, you can create PowerShell script files using virtually any text editor or the ISE console. However, the preferred option (thanks @jotaka for the heads up) to build scripts moving forward is to use the Visual Studio Code editor with the PowerShell extension.
Creating script with Visual Studio Code
Visual Studio Code — also known as VS Code — is a free and extensible cross-platform code editor that provides an environment to edit virtually any kind of programming language. And when adding the PowerShell extension, you get a fully interactive scripting editing experience, even with IntelliSense (code-completion) support.
The new experience is meant to be the new default, but the PowerShell ISE console isn’t going away. Still, the company won’t be adding any more features, and it doesn’t support PowerShell 7 or higher releases.
Install Visual Studio Code
To install Visual Basic Code on Windows 10, use these steps:
Click the Windows button to download the installer.
Source: Windows Central
Click the Next button.
Source: Windows Central
Confirm additional tasks as necessary.
Source: Windows Central
Once you complete the steps, you can proceed to install the PowerShell extension.
Install PowerShell extension
To install the PowerShell extension on VS Code, use these steps:
- Open VS Code.
- Click the Extensions tab from the left pane.
- Search for PowerShell and select the top result.
Click the Install button.
Source: Windows Central
After you complete the steps, you can start writing PowerShell scripts using Visual Studio Code.
Create PowerShell script with Visual Studio Code
To create a script with Visual Basic Code, use these steps:
- Open VS Code.
Click the File menu and select the New File option.
Source: Windows Central
Click the File menu and select the Save as option.
Source: Windows Central
Write a new, or paste the script you want to run — for example:
Write-Host «Congratulations! Your first script executed successfully»
The above script will output the phrase «Congratulations! Your first script executed successfully» on the screen.
(Optional) Click the Run button from the top-right side (or press the F5 key) to run the script.
Source: Windows Central
Creating script with Notepad
To create a PowerShell script using the Notepad editor on Windows 10, use these steps:
- Open Start.
- Search for Notepad, and click the top result to open the app.
Write a new, or paste your script, in the text file — for example:
Write-Host «Congratulations! Your first script executed successfully»
Source: Windows Central
Type a descriptive name for the script — for example, first_script.ps1.
Source: Windows Central
Creating script with Integrated Scripting Environment
Alternatively, you can use the built-in PowerShell ISE console to code your scripts on Windows 10.
The Integrated Scripting Environment is an advanced tool, but you can get started using these steps:
- Open Start.
- Search for Windows PowerShell ISE, right-click the top result, and select the Run as administrator option.
- Click on File menu.
Select the New option to create a new empty .ps1 file.
Source: Windows Central
Write a new, or paste the script you want to run — for example:
Write-Host «Congratulations! Your first script executed successfully»
Source: Windows Central
Type a name for the script – for example, first_script.ps1.
Source: Windows Central
Once you complete the steps using Notepad, Visual Studio Code, or PowerShell ISE, the script will be ready to run, but it will fail by default. This is because the default PowerShell settings are always set to block the execution of any script. (The only exception is if you run the contents of the script within Visual Studio Code or PowerShell ISE.)
How to run PowerShell script file on Windows 10
If you wish to run a script file with PowerShell, you have to change the execution policy on Windows 10.
To change the execution policy to run PowerShell scripts, use these steps:
- Open Start.
- Search for PowerShell, right-click the top result, and select the Run as administrator option.
Type the following command to allow scripts to run and press Enter:
Type A and press Enter (if applicable).
Source: Windows Central
Type the following command to run the script and press Enter:
In the above command, make sure to change «PATH\TO\SCRIPT» to the location of your script.
For example, this command runs a script stored in the Downloads folder:
Source: Windows Central
After you complete the steps, the script will run, and if it was written correctly, you should see its output without issues.
On Windows 10, PowerShell includes four execution policies, including:
- Restricted — Stops any script from running.
- RemoteSigned — Allows scripts created on the device, but scripts created on another computer won’t run unless they include a trusted publisher’s signature.
- AllSigned — All the scripts will run, but only if a trusted publisher has signed them.
- Unrestricted — Runs any script without any restrictions.
In the above steps, we use the command to allow local scripts to run on Windows 10. However, if you’re not planning to run scripts regularly, you can restore the default settings to block untrusted scripts using the same instructions outlined above, but on step No. 4, make sure to use the Set-ExecutionPolicy Restricted command.
More Windows 10 resources
For more helpful articles, coverage, and answers to common questions about Windows 10, visit the following resources:
Halo: MCC’s live service elements make it better, not worse
Halo: The Master Chief Collection is more popular than ever, but some fans don’t agree with the live service approach 343 Industries has taken with it. Here’s why those elements are, at the end of the day, great for the game and for Halo overall.
Microsoft’s Surface Duo is not ‘failing up’
Microsoft announced this week that it was expanding Surface Duo availability to nine new commercial markets. While Surface Duo is undoubtedly a work in progress, this is not a sign of a disaster. It’s also doesn’t mean that Surface Duo is selling a ton either. Instead, the reason for the expansion is a lot more straightforward.
Here’s what you can do if Windows 10 update KB5001330 is causing issues
In this guide, we’ll show you the steps to get rid of the update KB5001330 to fix profile, gaming, and BSoD problems with the Windows 10 October 2020 Update and May 2020 Update.
These are the best PC sticks when you’re on the move
Instant computer — just add a screen. That’s the general idea behind the ultra-portable PC, but it can be hard to know which one you want. Relax, we have you covered!