![](/img/trans.png)
[英]How do I call an elevated PowerShell from Windows command prompt to execute commands and a PowerShell script file?
[英]How do I execute a script from Windows Powershell?
我创建了一个小的aws.bat脚本,然后在PowerShell中导航到该脚本目录。
但是当我键入aws时,我收到一条错误消息,它不执行脚本。 我应该做些特别的事情吗?
这是我尝试过的:
PS C:\G> .\aws.bat
C:\G>$BucketName = "ab-user"
'$BucketName' is not recognized as an internal or external command,
operable program or batch file.
第一个命令和每个其他命令都有类似的消息。
您不能只输入名称(带或不带文件扩展名),您首先必须告诉powershell如何使用它。
您可以按以下方式调用它:
& .\aws.bat
如果您需要在powershell中返回的LastExitCode
来检查bat文件是否正常工作(通常0表示正常,否则通常无效),请使用Start-Process
,如下所示:
$batch = Start-Process -FilePath .\aws.bat -Wait -passthru;$batch.ExitCode
而且,如果要在Powershell运行该批处理文件时将其隐藏,请执行以下操作:
$batch = Start-Process -FilePath .\aws.bat -Wait -passthru -WindowStyle Hidden;$batch.ExitCode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.