Search code examples
windowsamazon-ec2ec2-userdata

How to set Environment Variables on EC2(window) instance via User Data


<powershell>
$file = $env:SystemRoot + "\Temp\" + (Get-Date).ToString("MM-dd-yy-hh-mm")
New-Item $file -ItemType file
</powershell>
<persist>true</persist>

I did not achieve the expected results using the above code. The expected file was not generated under this path C:\Windows\Temp\ in the instance


Solution

  • Your instance needs to install EC2Launch,and here is the Revised code:

    <powershell> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force $file = $env:SystemRoot + "\Temp\" + (Get-Date).ToString("MM-dd-yy-hh-mm") New-Item $file -ItemType file </powershell> <persist>true</persist>