AWS CLI - SSM Start Session - Execute Commands on EC2 instance after starting Session Manager using PowerShell Script

51 views Asked by At

I am writing a PowerShell script that access the file on ec2 instance using session manager with AWS CLI, calculate checksum of it and retrieve the checksum result.

I can be able to start the session using the PowerShell script but I am not sure how can I run PowerShell commands on EC2 instance using script?

$instanceId = "i-xxxxxxxxx"
$profile = "xxxxxxxx"
$filePath = "\path\to\file"

aws ssm start-session --target $instanceId --profile $profile
Get-FileHash -Path $filePath -Algorithm SHA256
    

I want to run "Get-FileHash -Path $filePath -Algorithm SHA256" command on EC2 instance using the PowerShell script and retrieve the result in PowerShell.

Can you provide me suggestions on how to execute PowerShell commands after establishing a session with EC2 instance using Session Manager With AWS CLI?

0

There are 0 answers