in cloud shell getting an error exec: "PowerShell": executable file not found in $PATH.

2022-06-28T19:08:09.623+00:00

I am trying to run powershell command inside Terraform local-exec.
resource "null_resource" "PowerShellScriptRunFirstTimeOnly" {
for_each = { for a in var.approxy: a.appname => a }
provisioner "local-exec" {
command = <<EOT
Import-Module AzureAD
#Start-Sleep -Seconds 1.5
Connect-AzureAD -username ******@sanswitzerlandoutlook.onmicrosoft.com -password ************
#command = "Write-Host \"Parameter 1 value is ${each.value.appname}\""

But I am getting an error saying "PowerShell": executable file not found in $PATH. ,Please help here

Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,926 Reputation points
    2022-06-29T15:18:50.13+00:00

    Hello,

    As a start you could double-check if you have installed the PowerShell Core successfully; if you have enough permission to access that pwsh file or directory; If the installed directory is added to the environment variable $PATH.

    You could run echo $PATH to check the current PATH configuration and run export PATH=$PATH:/xxx/xxx to add a directory into the $PATH.

    Also you can consider Installing Terraform on Windows with Bash
    https://learn.microsoft.com/en-us/azure/developer/terraform/get-started-windows-bash?tabs=bash

    Test Terraform modules in Azure using Terratest
    https://learn.microsoft.com/en-us/azure/developer/terraform/test-modules-using-terratest

    Alternative Terraform worker image TFE runs terraform plan and terraform apply operations in a disposable Docker containers. There are cases where runs may make frequent use of additional tools that are not available in the default Docker image. To allow use of these tools for any plan or apply, users can build their own image and configure TFE to use that instead. In order for this to happen the name of the alternative docker image must be set in the config by using the Custom image tag field

    -----------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.