How to install SSM agent on multiple EC2 instances

PowerShell Script to Install SSM Agent

1. Prepare CSV File: Create a CSV file containing a list of server names or IP addresses where you want to install the SSM agent. Save this file with a suitable name, for example, servers.csv. Ensure that the CSV file has a header (e.g., ServerName).

2. Install SSM Agent Script: Write a PowerShell script that reads the CSV file, iterates through each server, and installs the SSM agent.

Below is the PowerShell script that accomplishes this task:

 # Read server names from CSV file
$servers = Import-Csv -Path "C:\Path\to\servers.csv"

# Loop through each server and install SSM agent
foreach ($server in $servers) {
    $serverName = $server.ServerName
    Write-Host "Installing SSM agent on $serverName"
    # Use PowerShell remoting to install SSM agent on the remote server
    Invoke-Command -ComputerName $serverName -ScriptBlock {
        # Download SSM agent installer
        Invoke-WebRequest -Uri "" -OutFile "$env:TEMP\AmazonSSMAgentSetup.exe"
        # Install SSM agent
        Start-Process -FilePath "$env:TEMP\AmazonSSMAgentSetup.exe" -ArgumentList "/S" -Wait
    Write-Host "SSM agent installed on $serverName"

Replace "C:\Path\to\servers.csv" with the actual path to your CSV file.

Note: Ensure that you have appropriate permissions and network access to remotely install software on the target servers. Test the script in a non-production environment before deploying it to production servers.


2 responses to “How to install SSM agent on multiple EC2 instances”

  1. ashwani tyagi Avatar
    ashwani tyagi

    thank you for the script all helped me alot

  2. Ashwani Avatar

    Thank you for the script it helped me alot

Leave a Reply

Your email address will not be published. Required fields are marked *