# Terraform Remote-Exec for Windows devices

**URL:** <https://discuss.hashicorp.com/t/terraform-remote-exec-for-windows-devices/50169>\
**Category:** VMware\
**Created:** [February 14, 2023, 8:43pm UTC](https://discuss.hashicorp.com/t/terraform-remote-exec-for-windows-devices/50169 "2023-02-14T20:43:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chlalithkumar97](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chlalithkumar97](https://discuss.hashicorp.com/u/chlalithkumar97)\
**Post date:** [February 14, 2023, 8:43pm UTC](https://discuss.hashicorp.com/t/terraform-remote-exec-for-windows-devices/50169/1 "2023-02-14T20:43:18Z")

</div>

Terraform remote-exec for windows devices are failing to copy PowerShell file and execute in newly created device but the fact here Terraform continued after execution it indicates that the remote system reported that the script executed successfully.  
After successful Execution we checked the device and it shows no file in it.  
**### Expected Behavior**

[null\_resource.remote-exec[0] (remote-exec):[C:\Users\*\*\*\>powershell -ExecutionPolicy Unrestricted -File “c:/Users/AppData/Local/Temp/JoinDomain.ps1” “Domain.local” “[Testuser@Domain.local](mailto:Testuser@Domain.local)” “10.\*. **.** ”  
[null\_resource.remote-exec[0]: Still creating… [2m50s elapsed][0m  
[1mnull\_resource.remote-exec[0] (remote-exec):[0mWARNING: The changes will take effect after you restart the computer AUT-7580.  
[1mnull\_resource.remote-exec[0] (remote-exec):[0mVERBOSE: Performing the operation “Test-ComputerSecureChannel” on target “AUT-7580”.  
[1mnull\_resource.remote-exec[0] (remote-exec):[0mTrue  
[1mnull\_resource.remote-exec[0] (remote-exec):[0mVERBOSE: The secure channel between the local computer and the domain \*\*\*.local is in good condition.  
[1mnull\_resource.remote-exec[0]: Creation complete after 3m0s [id=6099486594879622166][[32m  
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.  
**### Actual Behavior**

[1mnull\_resource.remote-exec[0] (remote-exec):[0mC:\Users\nable\>powershell -ExecutionPolicy Unrestricted -File “c:/Users/_**/AppData/Local/Temp/JoinDomain.ps1" “Domain.local” “[Testuser@Domain.local](mailto:Testuser@Domain.local)” "10.**_”  
[1mnull\_resource.remote-exec[0]: Still creating… [1m50s elapsed][0m  
[1mnull\_resource.remote-exec[0]: Still creating… [2m0s elapsed][0m  
[1mnull\_resource.remote-exec[0]: Creation complete after 2m2s [id=406568817569139061][0m  
[32m  
Apply complete! Resources: 2 added, 0 changed, 0 destroyed

**##Configuration block we used in Terraform**  
resource “null\_resource” “remote-exec” {  
count = “${var.instances}” # this is the number of VMs i provision

connection {  
type = “winrm”  
user = var.admin\_user  
password = var.admin\_password  
host = one(vra7\_deployment.Windows\_Desktop[count.index].resource\_configuration)[“instances”][count.index][“ip\_address”]  
}  
provisioner “file” {  
source = “JoinDomain.ps1”  
destination = “c:/Users/\*\*\*/AppData/Local/Temp/JoinDomain.ps1”  
}

provisioner “remote-exec” {  
inline = [  
“powershell -ExecutionPolicy Unrestricted -File "c:/Users/_ **/AppData/Local/Temp/JoinDomain.ps1" "Domain.local" "Testuser@Domain.local" "10.** _.\*\*_._"”  
]  
}  
What can we do to fix this issue?  
We changed the path of the location to store file we mentioned but no luck.
