# Provisioner "remote-exec" - how to clean up temporary terraform files

**URL:** <https://discuss.hashicorp.com/t/provisioner-remote-exec-how-to-clean-up-temporary-terraform-files/20626>\
**Category:** HCP Terraform\
**Created:** [February 5, 2021, 4:36pm UTC](https://discuss.hashicorp.com/t/provisioner-remote-exec-how-to-clean-up-temporary-terraform-files/20626 "2021-02-05T16:36:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidmccarty](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/davidmccarty/32/16633_2.png) [@davidmccarty](https://discuss.hashicorp.com/u/davidmccarty)\
**Post date:** [February 5, 2021, 4:36pm UTC](https://discuss.hashicorp.com/t/provisioner-remote-exec-how-to-clean-up-temporary-terraform-files/20626/1 "2021-02-05T16:36:12Z")

</div>

I have some templates using null-resource and executing remote-exec commands via ssh or winrm. When the target execution is complete there are files left on the target systems  
e.g.  
`c:\temp\terraform_nnnnnnnn.cmd` on windows  
or  
`/tmp/terraform_nnnnnnnn.sh` on linux.

These are never cleaned up even if I run a destroy/delete on the template instance.

Is there a way to clean these up after the remote-exec has completed without errors?

Here is a sample template that outlines what we are doing …

```
 resource "null_resource" "TEST" {
   connection {
        type = "winrm"
        user = "Administrator"
        password = "passw0rd"
        host = "1.2.3.4"
   }
   provisioner "file" {
        source = "script.ps1"
        destination = "C:\\temp\\script.ps1"
   }
   provisioner "remote-exec" {
       inline = [ 
           "powershell.exe -File C:\\temp\\script.ps1"
      ] 
  }   
}
```
