我正在尝试做我的第一个脚本.简单地让PowerShell提取在记事本中输入的脚本并保存为标题为"test"的.ps1文件(也尝试过脚本,但知道名称与它无关):
Write-Host "Hello, World!"
Run Code Online (Sandbox Code Playgroud)
在PowerShell我输入
& "C:\Scripts\test.ps1"
Run Code Online (Sandbox Code Playgroud)
以及
./test.ps1
Run Code Online (Sandbox Code Playgroud)
我只遇到这个:
./test.ps1.txt : The term './test.ps1.txt' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ./test.ps1.txt
+ ~~~~~~~~~~~~~~
+ CategoryInfo: ObjectNotFound: (./test.ps1.txt:String) [], CommandNotFoundException
尝试过使用PowerShell重命名文件
PS C:\Scripts> Rename-Item test.ps1.txt test.ps1
Run Code Online (Sandbox Code Playgroud)
我曾经之间切换RemoteSigned和Unrestricted,我曾尝试包括代码executionpolicy bypass(我道歉,我闭上了窗口,而无需编写一个向下).据我所知,一切都是最新的,我正在运行Windows 10,Windows PowerShell和常规Windows记事本.