About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

How to domain join through MOF and Azure Automation account - DSC

Create a PowerShell File with name DomainJoinConfiguration.ps1

PS C:\Users\admina> Install-packageProvider -name Nuget

PS C:\Users\admina> Install-Module -Name xPSDesiredStateConfiguration -Force

PS C:\Users\admina>Install-Module -Name xDSCDomainjoin  -Force


Configuration DomainJoinConfiguration

param(
    [PSCredential]$DomainCredential
)
    Import-DscResource -ModuleName 'xDSCDomainjoin'
       
    node $AllNodes.NodeName 
    {
        xDSCDomainjoin JoinDomain
        {
            Domain = 'adven.com'
            Credential = $DomainCredential
         
        }
    }
}

$ConfigData = @{
    AllNodes = @(
        @{
            NodeName = "*"
            PSDscAllowPlainTextPassword = $True
            PSDscAllowDomainUser = $true
         
        }
        @{
            NodeName = "localhost"
        }
    )

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 C:\xfer\DomainJoinConfiguration.ps1

Then execute below command

$cred = Get-Credential -UserName kushagra@adven.com -Message "Password please"
DomainJoinConfiguration -DomainCredential $cred -ConfigurationData $ConfigData

Then

PS C:\Users\admina> DomainJoinConfiguration -DomainCredential $cred -ConfigurationData $ConfigData


    Directory: C:\Users\admina\DomainJoinConfiguration


Mode                LastWriteTime         Length Name                                                                             
----                -------------         ------ ----                                                                             
-a----         7/5/2020   7:31 PM           2220 iisserver01.mof                                                                   



PS C:\Users\admina> Start-DscConfiguration -Path C:\Users\admina\DomainJoinConfiguration -Force -Wait -Verbose



You will observe The VM is joined to Domain.


Through Azure Automation
~~~~~~~~~~~~~~~~~~~~~~
Create a Powershell file with name DomainJoinConfiguration

In Azure Automation account ensure xDSCDomainjoin is added in the module.

Configuration DomainJoinConfiguration
{   
    Import-DscResource -ModuleName 'xDSCDomainjoin'
   
    #domain credentials to be given here   
    $secdomainpasswd = ConvertTo-SecureString "lXXitech@XXX" -AsPlainText -Force
    $mydomaincreds = New-Object System.Management.Automation.PSCredential("l1user01@adven.com"$secdomainpasswd)
          
    node $AllNodes.NodeName   
    {
        xDSCDomainjoin JoinDomain
        {
            Domain = 'adven.com'
            Credential = $mydomaincreds
           
        }
    }
}

save the file as DomainJoinConfiguration.ps1
upload the file to Azure Automation account


from local laptop
Connect-AzureRmAccount -Tenant "8896b7ee-113f-XXXX-8fe2-05XXXXXccbcf01" -SubscriptionId "9239f519-XX04-XXXX-ae6f-c84XXXXX714" $ConfigData = @{ AllNodes = @( @{ NodeName = "*" PSDscAllowPlainTextPassword = $True PSDscAllowDomainUser = $true } @{ NodeName = "DomainJoined" } ) } $compilationJob = Start-AzureRmAutomationDscCompilationJob -ResourceGroupName 'NetworkWatcherRG' -AutomationAccountName 'storeusertokeyvault' -ConfigurationName 'DomainJoinConfiguration' -ConfigurationData $ConfigData $compilationJob








Press okay, you will observe selected VM is joined to domain.