简体   繁体   English

无法从CMD运行PowerShell脚本

[英]Not Able to Run PowerShell Script from CMD

I want to execute a PowerShell script from Command Prompt. 我想从命令提示符处执行PowerShell脚本。 I have verified script from PowerShell, it worked fine. 我已经从PowerShell验证了脚本,它工作正常。 I went to script location and executed it as 我去了脚本位置并执行了

./hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\0\0\D")

But when I tried running it from command prompt as 但是当我尝试从命令提示符运行它时

powershell.exe C:\hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\0\0\D")

it gave me an error 它给了我一个错误

ERROR: Failed to find object of [Microsoft:7B036CE0-5D67-46BA-AF7BB2AFD8DD794683F8638B-8DCA-4152-9EDA-2CA8B33039B400D] disk which is associated with [{6612D0CB-BCC3-44D4-988B-526500578D54}] VM. 错误:无法找到与[{6612D0CB-BCC3-44D4-988B-526500578D54}]关联的[Microsoft:7B036CE0-5D67-46BA-AF7BB2AFD8DD794683F8638B-8DCA-4152-9EDA-2CA8B33039B400D]磁盘的对象。

Both are exact same but why it is not running from Command Prompt? 两者是完全相同的,但是为什么它不能从命令提示符运行?

Try running from the command prompt with double backslashes, like so: 尝试从命令提示符运行带有两个反斜杠的命令,如下所示:

powershell.exe C:\\hyperv_disk_ops.ps1 -op 'getDiskAttachmentInfo' -vmid '{6612D0CB-BCC3-44D4-988B-526500578D54}' -disk_ids ("Microsoft:7B036CE0-5D67-46BA-AF7B-B2AFD8DD7946\\\\83F8638B-8DCA-4152-9EDA-2CA8B33039B4\\\\0\\\\0\\\\D")

It looks like, in the error you provided, all of the slashes are being omitted in the disk path. 在您提供的错误中,磁盘路径中的所有斜杠似乎都被省略了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM