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
$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.
Press okay, you will observe selected VM is joined to domain.
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
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:
Post a Comment