Install and setup SMTP on a windows server using Powershell DSC

Jessey Clarke 21 Reputation points
2023-08-02T20:00:20.2633333+00:00

I am currently using Azure Automation State configuration (DSC) to setup a SMTP server. Installing the feature has been fine but I cant seem to find how to configure the SMTP settings such as the virtual server, relay info etc. So I'm wondering if anyone has ever achieved this?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,129 questions
Windows Server Management
Windows Server Management
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Management: The act or process of organizing, handling, directing or controlling something.
421 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,383 questions
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,386 Reputation points
    2023-08-31T04:33:00.2033333+00:00

    Hi @Jessey Clarke ,

    Yes, xSMTPServer inbuilt DSC resource doesn't exist. In this use case, you might want to write a PowerShell DSC configuration script that specifies the desired SMTP settings that could involve setting up the virtual server, configuring relay information, and any other necessary SMTP-related settings. As Azure Automation DSC allows you to use the Custom Script Extension to run custom scripts on target machines so you can use this extension to execute your DSC configuration script. The custom script extension can be used to invoke your DSC configuration script, which will then ensure the desired SMTP settings are configured on the target machine.

    Sample DSC configuration:

    Configuration ConfigureSMTP {
        Import-DscResource -ModuleName PSDesiredStateConfiguration
    
        Node 'TargetNode' {
            Script SetupSMTP {
                SetScript = {
                    # Your PowerShell code to configure SMTP settings
                    # This might involve configuring IIS for SMTP, setting up virtual servers, relay settings, etc.
                }
                TestScript = {
                    # Test the current state to determine if configuration is required
    				# TestScript should evaluate to $false when the desired state is already achieved
                    $false
                }
                GetScript = { }
            }
    
            SetupSMTP
        }
    }
    
    ConfigureSMTP -OutputPath C:\DSCOutput
    
    
    0 comments No comments