Commands for First Launching

Last updated: 2020-02-25 12:16:09



When you create Cloud Virtual Machine, you can specify Custom data To configure the instance When Cloud Virtual Machine Launch for the first time The custom data is passed to Cloud Virtual Machine as text and the text is executed. If you buy more than one Cloud Virtual Machine at a time, the custom data will run the text when all Cloud Virtual Machine first Launch.
This paper takes Windows Cloud Virtual Machine's first Launch as an example by passing a script in PowerShell format.


  • Windows operating systems that support custom data include:
    Windows Server 2012 R2 data center 64-bit English version
    Windows Server 2012 R2 DataCenter 64-bit Chinese
  • Only for the first time, Launch and Cloud Virtual Machine, execute the order by passing the text.
  • Before Base64 encoding, custom data content cannot exceed 16KB.
  • Custom data is passed through Base64 encoding. If you copy a non-base64 script file directly, please uncheck [enter as base64 format text].
  • In Launch, executing job specified in the custom data will increase the time required for Launch's server. It is recommended that you wait a few minutes and test whether job has been successfully executed after job has finished.
  • In this example, use the PowerShell tag to specify the Windows PowerShell script, for example < Powershell >< / powershell > Tags.


Prepare text

Please prepare the text according to your actual needs:

PowerShell script

Using the PowerShell tag, prepare a PowerShell script file.
For example, you need to create a content called "Hello Tencent Cloud." in Cloud Virtual Machine's C: disk. , you can use the PowerShell tag to prepare the following

"Hello Tencent Cloud." | Out-File  C:\tencentcloud.txt

Base64 encoding script

  1. Execute the following command to create a PowerShell script file named "script_text.ps1".
vi script_text.ps1
  1. By I Switch to edit mode, refer to the following, and write and save the "script_text.ps1" script file.
"Hello Tencent Cloud." | Out-File  C:\tencentcloud.txt
  1. Execute the following command to Base64 encode the "script_text.ps1" script file.
base64 script_text.ps1

The following information is returned:


Transfer text

We provide a variety of Launch examples, mainly divided into the following two cases. Please choose according to your actual needs:

Passing on the official website or the console

  1. Refer to Create instances Purchase an instance and go to "4." Click Advanced Settings in set Security groups and hosts.
  2. In Advanced Settings, enter the prepared text content in the text box of Custom data, depending on your actual needs.
  1. Operate step by step according to the interface information to complete the creation of Cloud Virtual Machine.

Passing via API

When you create Cloud Virtual Machine through API, you can set the Base64 encoding script The encoding result returned in is assigned to the UserData parameter of the RunInstances interface to pass the text.
For example, create a request parameter of Cloud Virtual Machine with UserData parameter. The example is as follows:
  &<common request parameters>

Verify custom data configuration

  1. Log in to the CVM.
  2. In the operating system interface, open the C:\ disk to see if it exists. tencentcloud.txt Text file.
    If it exists tencentcloud.txt Text file, the configuration is successful.