About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

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.


No comments: