Skip to content

Git not found when running PowerShell script using AWS Systems Manager Run Command

0

Description: I have installed Git on my EC2 instance, and I've verified that it's installed correctly by running git --version directly on the instance. However, when I run a PowerShell script using AWS Systems Manager Run Command, Git is not found.

I've ensured that Git's installation path is added to the system's PATH environment variable, but it still doesn't seem to work when running PowerShell scripts via AWS Systems Manager.

Could someone please advise on how to troubleshoot and resolve this issue? Any suggestions or insights would be greatly appreciated.

asked 2 years ago450 views
2 Answers
2

Hello.

Try restarting EC2 after adding the Git path to the environment variables.
After adding Git to the system environment variable path, I restarted EC2 and executed Systems Manager RunCommand, and the Git command was executed successfully.
https://stackoverflow.com/questions/58293277/use-systems-manager-to-run-aws-cli-commands-on-windows-ec2-instance
https://stackoverflow.com/questions/4492979/error-git-is-not-recognized-as-an-internal-or-external-command
a
a

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
  • If the settings are configured correctly, you can check the Git version as shown below. a

1

Verify PATH Environment Variable:

Connect to your EC2 instance and run the following command in PowerShell:

$env:Path

Check Script Execution Policy:

Run the following command to check your script execution policy:

Get-ExecutionPolicy

Explicitly Call Git:

Instead of relying on the PATH environment variable, explicitly call the Git executable within your script. PowerShell

& "C:\Program Files\Git\bin\git.exe" --version

For more to troubleshoot the issue follow the link:

https://docs.aws.amazon.com/systems-manager/latest/userguide/troubleshooting-ssm-agent.html

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.4

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.