如何运行PowerShell脚本? shell
powershell.exe 'C:\\my_path\\yada_yada\\run_import_script.ps1'
(带或不带--noexit
) 除了输出文件名外,它什么都不返回。 app
没有错误,没有消息,没有。 哦,当我添加-noexit
,一样的事情发生了,但我仍然在PowerShell中而且必须手动退出。 框架
.ps1文件应该运行程序并返回依赖于该程序输出的错误级别。 但我很肯定我尚未到达那里。 异步
我究竟作错了什么? spa
给出脚本的路径,即cmd的路径设置: code
$> . c:\\program file\\prog.ps1
ip
运行PowerShell的入口点功能: get
例如, $> add or entry_func or main
cmd
导航到脚本所在的目录 博客
PS> cd C:\\my_path\\yada_yada\\ (enter)
执行脚本:
PS> .\\run_import_script.ps1 (enter)
我错过了什么?
或者:您能够从cmd.exe
运行PowerShell脚本,以下所示:
powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)
根据这篇博客文章
或者您甚至能够从C#app运行Powershell脚本:-)
若是您使用PowerShell 2.0,请使用PowerShell.exe的-File参数从其余环境(如cmd.exe)调用脚本,例如:
Powershell.exe -File C:\my_path\yada_yada\run_import_script.ps1
我遇到了一样的问题,我尝试过并试过......最后我使用了:
powershell.exe -noexit "& 'c:\Data\ScheduledScripts\ShutdownVM.ps1'"
并将此行放在批处理文件中,这是有效的。
使用cmd(BAT)文件:
@echo off color 1F echo. C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "PrepareEnvironment.ps1" :EOF echo Waiting seconds timeout /t 10 /nobreak > NUL
若是您须要以管理员身份运行 :