首页 文章

在terraforms中执行cmd文件

提问于
浏览
0

我在Vsphere上配置了带有terraforms的Windows Server 2012R2 . 我让机器启动并运行 . 现在我想通过remote_exec terraforms在机器上运行一些.cmd文件 .

用户不是管理员,而是管理员组 . UAC已禁用,以便通过CLI或PowerShell执行脚本 .

我编写了一个runAsAdmin.ps1,它将调用我的install_software.ps1,它将具有执行.cmd文件所需的所有命令 .

runAsAdmin.ps1

powershell -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -file C:\scripts\install_software.ps1' -verb RunAs}"

install_software.ps1

cd C:\\gitrepo\\lip-core-devops\\terraform\\system-config\\ims\\scripts
 echo "Installing IMS Base from powerscript"
 Invoke-Item .\Install_IMS_Base.cmd

我可以直接在机器上的powershell上运行runAsAsAdmin.ps1而无需管理员提升,一切都按预期工作 .

但是当我从terraforms的remote-exec执行runAsAdmin.ps1时,执行成功,但是不执行install_software文件的内容 . 我尝试在执行cmd文件之前创建一个目录 .

Terraform部分

provisioner "remote-exec" {
inline = [
  "powershell -File C:\\scripts\\runAsAdmin.ps1"
}

连接全部设置并成功 . 我在脚本执行结束时获得了成功 .

我在脚本中缺少的是它不是通过terraforms执行,而是在机器上运行 .

1 回答

  • 0

    这可能是由powershell执行策略引起的,请尝试使用-ExecutionPolicy设置运行它 . 在Azure中使用VM扩展时,我必须这样做 .

    start powershell -ExecutionPolicy Unrestricted -File runAsAdmin.ps1

相关问题