1

I have a script that uses invoke-request to get a remote ID string. How can I retrieve the value of instanceID and set it to (SET instanceId) within .bat script

powershell $instanceId =(Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/instance-id).Content exit

TNKS

1 Answer 1

2
  • The variable isn't set in PoSh - but simply output.
  • The batch wraps the powershell command in a parsing for /f loop and sets a batch variable.

@Echo off
For /f "usebackqdelims=" %%A in (
  `Powershell.exe -nologo -NoProfile -command "(Invoke-WebRequest -Uri http://169.254.169.254/latest/meta-data/instance-id).Content"`
) Do Set InstanceID=%%A
Echo InstanceID=%InstanceID%
Pause
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .