# Windows Environment Variables not accessible when Logstash is run as a service

**URL:** <https://discuss.elastic.co/t/windows-environment-variables-not-accessible-when-logstash-is-run-as-a-service/302901>\
**Category:** Logstash\
**Created:** [April 21, 2022, 11:14am UTC](https://discuss.elastic.co/t/windows-environment-variables-not-accessible-when-logstash-is-run-as-a-service/302901 "2022-04-21T11:14:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![usman1](https://avatars.discourse-cdn.com/v4/letter/u/c67d28/32.png) [@usman1](https://discuss.elastic.co/u/usman1)\
**Post date:** [April 21, 2022, 11:14am UTC](https://discuss.elastic.co/t/windows-environment-variables-not-accessible-when-logstash-is-run-as-a-service/302901/1 "2022-04-21T11:14:32Z")

</div>

I have used Windows environment variables in Logstash config file. Following command was used to create env variable:  
` $env:MW_Index = 'mw-test-index-temp'`

In my config file, I have called this index.  
`mutate { add_field => { "[@metadata][target_index]" => "${MW_INDEX}" } }`

Now, when I run the Logstash from command line, it works fine but running it as a service does not ingest data. Following command is being used to run it as a service:  
`Start-Service -name logstash`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 19, 2022, 11:14am UTC](https://discuss.elastic.co/t/windows-environment-variables-not-accessible-when-logstash-is-run-as-a-service/302901/2 "2022-05-19T11:14:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
