0

I am trying to execute a powershell script from a terraform script. The powershell commands in the file is not being recognized while execution. Below is the code:

resource "null_resource" "example2" {
  provisioner "local-exec" {
    
    command = "powershell -file ./sample.ps1"
  }
}

Below is the error: null_resource.example2 (local-exec): Add-AzIotHubDevice : The term 'Add-AzIotHubDevice' is not recognized as the name of a cmdlet, function, script file, or operable

enter image description here

1 Answer 1

1

I think this is already answered here: How to run a powershell script in terraform?

Also, I recommend calling the exact powershell .exe you want. Some servers have PowerShell v5 and v7. Execution policy can cause issues too.

Recommend command that you can combine with the other answer: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file "./sample1.ps" -ExecutionPolicy "Bypass"

another example: https://ripon-banik.medium.com/run-powershell-script-in-terraform-54d6586c2827

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.