Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to write a PowerShell script that will run when a Windows 2012 instance is created on AWS using the configuration tools provided by AWS.

My problem is that I want to change the name of the machine once it has started up, restart the machine and carry on set up process after. The main reason for this is that one of the applications, Boundary, installed in the set up process takes the name of the server when first installed. It is then doesn't seem possible to change it's name in their portal.

Ideally I would have two PowerShell scripts, one to start the set up process, initialised through AWS and another that runs the first time the machine restarts. This second script would ideally be queued to run on the next start by the initial set up script. So I guess my question are:

  1. Is this possible?
  2. How would I go about doing this.

My Google foo is letting me down here so any answers would be appreciated.

share|improve this question
    
AWS just announced support for PowerShell to control most of the services including EC2: aws.amazon.com/powershell –  Guy Dec 6 '12 at 12:05
    
@Guy I'm aware of this, however it doesn't help as I still need to install a script to run after start up. In this situation they would not be helpful as I'm not interacting with any other AWS service after spinning up an instance and the instance needs to set itself up without user interaction –  James Toyer Dec 6 '12 at 12:35
add comment

1 Answer

It is definitely possible. The basic building blocks you will need are:

  • Amazon's 'User Data' feature, which enables running a user defined script when the instance first launches. There are more details here: https://forums.aws.amazon.com/message.jspa?messageID=342503 .
  • Windows Task Scheduler to schedule a task to execute after Windows restarts. Look at the schtasks.exe command for more details on how to do this (Just type schtasks.exe at the command prompt).

You will need two scripts:

  1. Runs via the 'User Data' feature. Responsible for scheduling the execution of the second script using the windows task scheduler on Windows start up, changing the Windows machine name and restarting Windows. The scheduling command should look something like:

    schtasks.exe /create /TN my-task /SC ONSTART /TR SCRIPT_FILE /RU USERNAME /RP PASSWORD

  2. Runs your applications.

The second script may also delete the scheduled task - depends if you want this VM to recover automatically from restarts or not.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.