【问题标题】:Unable to execute multi-command in power shell无法在powershell中执行多命令
【发布时间】:2014-01-14 05:48:00
【问题描述】:

我正在使用 windows 2012 服务器编写 power shell 脚本,它执行简单的两个功能

  • 以管理员身份打开 powershell
  • 将目录更改为 c:\user\scrpt.bat

代码是:

powershell -Command "& {powershell Start-Process PowerShell -Verb RunAs; Set-Location C:\}

问题不在于执行第一部分,而在于另一部分:

Set-Location C:\}

我的问题是在以管理员身份运行 powershell 执行下一条命令后有什么办法吗?

我已经尝试使用分号“;”但没有运气

【问题讨论】:

  • 如果您正在运行 .bat 文件,为什么不将所有这些都放在 .bat 文件中?

标签: windows powershell command


【解决方案1】:

如果您想更改正在生成的进程的目录 - 使用 -WorkingDirectory 选项:

powershell -Command "& { Start-Process PowerShell -Verb RunAs -WorkingDirectory 'D:' }"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2022-01-17
    • 2018-06-08
    • 1970-01-01
    相关资源
    最近更新 更多