[Azure] Azure Automation Step Note

[Azure] Azure Automation Step Note #Azure Automation
  • Step 1 Creating the resources
az group create \
    --name "invx-rg" \
    --location "southeastasia"

--create vm 
az vm create \
    --name "invx-vm" \
    --resource-group "invx-rg" \
    --location "southeastasia" \
    --image "Win2019Datacenter" \
    --size "Standard_B1ls"
  • Step 2 Creating the automation account
az automation account create \
    --automation-account-name "invx-aa" \
    --resource-group "invx-rg"
    --location "southeastasia" \
    --sku "Free"
  • Step 3 Create the state configuration
Configuration InvxWebAPIDscConfiguration
{
    param
    (
       [string[]]$ComputerName='localhost'
    )
   
    Node WEBAPP
    {
       WindowsFeature IIS
       {
          Ensure = 'Present'
          Name = 'Web-Server'
          IncludeAllSubFeature = $true       
       }
   
       WindowsFeature Bitlocker
       {
          Ensure = 'Present'
          Name = 'Bitlocker'
       }
    }
}
  • Step 4 Importing the configuration file
Import-AzAutomationDscConfiguration
    -SourcePath "C:\Config\InvxWebAPIDscConfiguration.ps1"
    -ResourceGroupName invx-rg
    -AutomationAccountName invx-aa
    -Published
  • Step 5 Compiling the configuration file - ถ้าระหว่าง Process จะนานนิดนึง ตรวจสถานะโดยใช้คำสั่ง Get-AzAutomationDscNodeConfiguration
Start-AzAutomationDscCompilationJob
    -ConfigurationName InvxWebAPIDscConfiguration
    -ResourceGroupName invx-rg
    -AutomationAccountName invx-aa
Get-AzAutomationDscNodeConfiguration
    -ResourceGroupName invx-rg
    -AutomationAccountName invx-aa
  • Step 6 Register the virtual machine เข้าไปใน VM ที่สร้าง
    • ConfigurationMode - ใช้ ApplyAndAutocorrect ให้มัน Dsc จัดการให้เลย
Register-AzAutomationDscNode
    -AzureVMName invx-vm
    -ResourceGroupName invx-rg
    -AutomationAccountName invx-aa
    -NodeConfigurationName InvxWebAPIDscConfiguration.WEBAPP
    -ConfigurationMode ApplyAndAutocorrect
    -RebootNodeIfNeeded $True

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.