Search code examples
dscazure-automation

Getting computername in Azure Automation DSC


I´m trying to use Azure Automation Pull server to add DSC configuration to a VM. Normally you can get the name of the current machine with the environment variable $env:COMPUTERNAME - i.e. like this:

xComputer JoinDomain
{ 
    Name  = $env:COMPUTERNAME
    DomainName = $ConfigurationData.NonNodeData.DomainDetails.DomainName             
    Credential    = $domainAdminCredential  
} 

But when using Azure Automation $env:COMPUTERNAME seems to always return CLIENT regardless of the current machine name. What is the best/most recommended approach to dynamically get the name of the current VM within the DSC configuration when using Azure Automation?

Thanks in advance.

Best regards,

Thomas


Solution

  • In summary a DSC configuration is applied as under:

    1. Author the configuration in PowerShell
    2. Compile the configuration - this generates a mof file
    3. Deliver the mof file to the LocalConfigurationManager (LCM) which enacts the same

    The code specified actually gets the name of the computer in step #2. Note that #2 can happen in a different computer than the one where you want to apply the configuration. In this case it happens to be the one on the AA service side.

    Unfortunately, at the moment there is no way to obtain the name of the computer in which the configuration is executing unless you choose to use the script resource. So in summary you can either specify the computer name via configuration data or do the domain join using a script resource