Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何从cmd执行ps1文件?_Powershell_Cmd_Exec_Ps1 - Fatal编程技术网

Powershell 如何从cmd执行ps1文件?

Powershell 如何从cmd执行ps1文件?,powershell,cmd,exec,ps1,Powershell,Cmd,Exec,Ps1,我有一个ps1文件Test.ps1,我需要从cmd执行它。出于测试目的,此文件只有一行: write "ps1 test successful" 我试图从cmd执行这个ps1文件。我在谷歌上搜索,似乎包括以下几行可能会有所帮助: Set-ExecutionPolicy RemoteSigned write "ps1 test successful" 但是,我仍然无法执行此测试。我试过: powershell Test powershell Test.ps1 Test Test.ps1 cm

我有一个ps1文件Test.ps1,我需要从cmd执行它。出于测试目的,此文件只有一行:

write "ps1 test successful"
我试图从cmd执行这个ps1文件。我在谷歌上搜索,似乎包括以下几行可能会有所帮助:

Set-ExecutionPolicy RemoteSigned
write "ps1 test successful"
但是,我仍然无法执行此测试。我试过:

powershell Test
powershell Test.ps1
Test
Test.ps1
cmd路径上下文设置为ps1脚本所在的目录。你知道我可能做错了什么吗?

使用

powershell.exe -ExecutionPolicy Bypass -File "C:\dir name\test.ps1"
当然,将
C:\dir name\test.ps1
替换为要运行的脚本的路径和文件名,并用
(双引号)括起来

或者,在自己的窗口中启动PowerShell,然后运行脚本。

这是否有效

Powershell-ExecutionPolicy Bypass-File。\Test.ps1

我以前使用.bat文件执行过此操作,这是使用的语法。在本例中,您是从与powershell脚本相同的目录中运行的(否则,请根据需要调整filename参数)。如果尚未运行,您可能需要以admin的身份运行CMD提示符