This topic describes how to prepare user-data scripts for Windows instances and how to pass in user data and verify the result of running the user data.
Prerequisites
Background information
The following limits apply to user data:
- The user data feature is supported only for instances that reside in virtual private clouds (VPCs).
- The instances must be created from the following public images or custom images derived
from public images:
- Alibaba Cloud Linux, CentOS, Ubuntu, SUSE Linux Enterprise, OpenSUSE, and Debian
- Windows Server 2008 R2 and later
- The user data feature is supported for all available instance types. For retired instance types, the user data feature is supported only for I/O-optimized instances. For more information, see Retired instance types.
- The user data that you want to run must be encoded in Base64. The size of the user
data cannot exceed 16 KB before it is encoded.
Note You can enter the user data that has not been encoded in Base64 in the console. The console automatically encodes the user data in Base64. If you do not want to enter the user data in the console, you must encode it in Base64 on your own.
Procedure
Bat
Batch scripts have the following characteristics:
- The first line starts with
[bat]
, and the header cannot have spaces. - Only half-width letters can be entered, and no additional characters are allowed.
Example:
[bat]
echo "bat test" > C:\userdata_test.txt
The example batch script can be run to write 
"bat test"
to the userdata_test.txt file when the instance starts for the first time, as shown in the following figure.

PowerShell
PowerShell scripts have the following characteristics:
- The first line starts with
[powershell]
, and the header cannot have spaces. - Only half-width letters can be entered, and no additional characters are allowed.
Example:
[powershell]
write-output "powershell test" | Out-File C:\userdata_test.txt
The example PowerShell script can be run to write 
powershell test
to the userdata_test.txt file when the instance starts for the first time, as shown in the following figure.
