1

I need to deploy Azure hosts and configure them according to a pre-defined script once they are loaded.

Is there any example, guidance,or tutorial on how to modify an Azure VM once the instance is deployed... programmatically (via powershell, c# or any other means)?

So far, I've gone through the command-line deployment commands, and don't see a way that I could upload or otherwise launch a post deployment installation command.

3 Answers 3

3

I'm not entirely sure where you've gotten stuck or what specifically you're trying to accomplish, but I'll give it a shot anyway...

Remote Desktop

Just for kicks, let's start with remoting in to the VM. I've spun up a VM using the Azure portal. The portal asks for a username and password to be specified. Obviously, the simplest way to remote in would be using the 'Connect' button after selecting an instance of your VM:

enter image description here

From there you could input your credentials, log in to the VM, and open up PowerShell.

That's a bad way of taking care of it, but it is the most straightforward.

PowerShell Remoting

Starting a remote PowerShell session could be a little quicker and involve less GUI. For a quick one-liner, try this:

Enter-PSSession -ConnectionUri (Get-AzureWinRMUri) -SessionOption (New-PSSessionOption -SkipCACheck) -Credential (Get-Credential)

You'll be prompted for the service name (in my case, rtannerf) and credentials. I opted to ignore the self-signed certificate rather than importing it.

You can also use Invoke-Command:

 Invoke-Command –ConnectionUri $uri –Credential $cred –ScriptBlock { "do u liek mah hat!?" | Out-File C:\hello.txt }

More on this here. You could expand upon this and use PowerShell to both deploy your VMs and run scripts against them once deployment is finished. Might want to take a look at the Azure Management cmdlet reference page.

This approach seems a little clunky to me, but if you need to kick off just a few VMs it might work out fine for you.

Deploying via Images

If you need a heavier touch than is appropriate for Invoke-Command, you may want to look in to deploying images. Short version is you'll prepare an image the way you would just about any other Windows image, upload it to a storage account in Azure, and use the management console to add the VHD to your images. There's a short guide here.

It sounds to me like this will be the way you want to approach your problem. You could use startup scripts and whatnot to get the machine in to the state you want, but it's probably better to cut to the chase and simply deploy an image that's configured exactly how you need it.

1
  • 1
    I think PowerShell Remoting with the link you gave me is just what I needed. Thanks! Jan 31, 2014 at 0:31
2

When deploying a VM, you can specify custom data: Up to 64K of data that's injected into the VM during provisioning (API details here). You specify data in a base-64 encoded format in the <CustomData> element. This data will then appear in your VM, in:

  • %SYSTEMDRIVE%\AzureData\CustomData.bin (Windows)
  • /var/lib/waagent/CustomData (Linux)

This is currently only available via the REST API directly, but will soon also be available via the cross-platform CLI. You can see the pull request for this feature here.

2
  • Thanks for the tip! Once I put the bin file there, what can I do with it? Thinking out loud, perhaps I could rename it to .zip or exe and run it remotely as described in the other answer Jan 31, 2014 at 14:33
  • 1
    It's your file to do as you wish. You could have a simple text file with a connection string; maybe a json config file; a puppet script; zip file; exe... I'd suggest trying it out with some simple text to see it in action. Feb 1, 2014 at 14:46
0

Alternative way, use IaaS Management Studio, it generates the command line so you can connect via powershell in one click. (and generate the command lines for it) Commercial, but maybe the free trial is enough for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .