Azure / azure-quickstart-templates

Azure Quickstart Templates
https://aka.ms/azqst
MIT License
14.05k stars 16.12k forks source link

additionalUnattendContent FirstLogonCommands example #1407

Open bdanse opened 8 years ago

bdanse commented 8 years ago

Hi, could someone provide a working example of a VM using additionalUnattendContent. For some reason I'm unable to get the FirstLogonCommands working. Always receive an error: 'The value of parameter windowsConfiguration.additionalUnattendContent.content is invalid.'

        "additionalUnattendContent": [
          {
            "passName": "oobeSystem",
            "componentName": "Microsoft-Windows-Shell-Setup",
            "settingName": "FirstLogonCommands",
            "content": "<FirstLogonCommands><AsynchronousCommand wcm:action=\"add\"><CommandLine>powershell</CommandLine><Description></Description><Order>1</Order></AsynchronousCommand></FirstLogonCommands>"
          }

Also tried to base-64 encode the content string. Same error.

additionalUnattendContent

  • pass Specifies the name of the pass that the content applies to. The only allowable value is oobeSystem.
  • component Specifies the name of the component to configure with the added content. The only allowable value is Microsoft-Windows-Shell-Setup.
  • settingName Specifies the name of the setting to which the content applies. Possible values are: FirstLogonCommands and AutoLogon.
  • content Specifies the base-64 encoded XML formatted content that is added to the unattend.xml file for the specified path and component.
singhkays commented 8 years ago

@bdanse The way I understand is that the XML value for content needs to be base64 encoded. What was the error you got?

bdanse commented 8 years ago

1e attempt : "content": "<FirstLogonCommands><AsynchronousCommand wcm:action=\"add\"><CommandLine>dir</CommandLine><Description></Description><Order>1</Order></AsynchronousCommand></FirstLogonCommands>"

2e attempt with encoding

"content": "base64('<FirstLogonCommands><AsynchronousCommand wcm:action=\"add\"><CommandLine>dir</CommandLine><Description></Description><Order>1</Order></AsynchronousCommand></FirstLogonCommands>')"

Both result in the same error : 'The value of parameter windowsConfiguration.additionalUnattendContent.content is invalid.'

singhkays commented 8 years ago

@bdanse base64 usage looks off. Expressions are enclosed with brackets ([ and ]).

Try "content": "[base64('<FirstLogonCommands><AsynchronousCommand wcm:action=\"add\"><CommandLine>dir</CommandLine><Description></Description><Order>1</Order></AsynchronousCommand>/FirstLogonCommands>')]"

If that doesn't work, then try base64 the value outside of the function and then paste that value in to the string.

bdanse commented 8 years ago

Tried making a parameter for the xml and let visual studio encode the xml. Then used that string and the base64 encoded variant.

Tried encoding it outside arm. still same error.

azuredeploy.txt

bdanse commented 8 years ago

Changed the AsynchronousCommand tag to SyschronousCommand.

"firstLogonXml": "<FirstLogonCommands><SynchronousCommand wcm:action=\"add\"><CommandLine>c:\\Windows\\notepad.exe</CommandLine><Order>1</Order></SynchronousCommand></FirstLogonCommands>"

Keeps giving the same error : 'The value of parameter windowsConfiguration.additionalUnattendContent.content is invalid.'

gregjhogan commented 8 years ago

Is this a parsing error caused by the colon in wcm:action?

The below JSON passes validation and did actually execute the command, so it appears it is acceptable to remove the wcm:action attribute, and perhaps that is a work-around for now.

{
  "passName": "oobesystem",
  "componentName": "Microsoft-Windows-Shell-Setup",
  "settingName": "FirstLogonCommands",
  "content": "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>"
}

Someone should also update the documentation, because clearly it should not be base64 encoded.

bdanse commented 8 years ago

@gregjhogan thank you that did the trick for now. @singhkay I have to agree with gregjhogan. additionalUnattendContent needs some work.

singhkays commented 8 years ago

@bdanse @gregjhogan Thanks for the investigation. I'll get the windows agent team to look at this.

bartrumb commented 8 years ago

I would like to use multiple "additionalUnattendContent" paramters. One to set the AutoLogon and one to set the FirstLogonCommand. Could somebody please provide an example?

bartrumb commented 8 years ago

I think I figured out how to do the multiple components but I'm having trouble with the computer actually logging in. Here is code in case anybody else is trying. This goes into the virtual machine resource:

"osProfile": { "computerName": "[concat(variables('TierBEName'), copyindex(1))]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]", "windowsConfiguration": { "provisionVMAgent": true, "additionalUnattendContent": [ { "passName": "oobesystem", "componentName": "Microsoft-Windows-Shell-Setup", "settingName": "AutoLogon", "content": "<AutoLogon><Password><Value>[parameters('adminPassword')]</Value></Password><Domain>[concat(variables('TierBEName'), copyindex(1)))]</Domain><Enabled>true</Enabled><LogonCount>3</LogonCount><Username>[parameters('adminUsername')]</Username></AutoLogon>" }, { "passName": "oobesystem", "componentName": "Microsoft-Windows-Shell-Setup", "settingName": "FirstLogonCommands", "content": "<FirstLogonCommands><SynchronousCommand><CommandLine>shutdown /r /t 0 /c \"initial reboot\"</CommandLine><Description>reboot</Description><Order>1</Order></SynchronousCommand></FirstLogonCommands>" } ] } },

gregjhogan commented 8 years ago

You have to concat() the "content" together when you want to use variables, for example:

{
    "passName": "oobesystem",
    "componentName": "Microsoft-Windows-Shell-Setup",
    "settingName": "AutoLogon",
    "content": "[concat('<AutoLogon><Domain>', variables('vmName'), '</Domain><Username>', parameters('adminUsername'), '</Username><Password><Value>', parameters('adminPassword'), '</Value></Password><LogonCount>3</LogonCount><Enabled>true</Enabled></AutoLogon>')]"
}