【发布时间】:2018-09-17 21:22:55
【问题描述】:
我正在远程执行一些脚本,以使用 putty 中的 Plink 工具从服务器获取信息。当我使用 .ps1 文件时,问题就来了,因为一个“?”出现在开头,使第一行不正确,但使用 .bat 文件可以正常工作。
比如我要打印一个文件的内容:
GetDate.bat:
type C:/Data/DateOfCompilation.txt
然后:
PS C:/Users/MyUser> plink -ssh <User>@<IP> -i C:\Key.ppk -m C:\Scripts\GetDate.bat
10/09/2018 14:32:02,72
一切正常
GetDate.ps1:
Get-Content -Path C:/Data/DateOfCompilation.txt
执行:
PS C:/Users/MyUser> plink -ssh <User>@<IP> -i C:\Key.ppk -m C:\Scripts\GetDate.ps1
?Get-Content : The term '?Get-Content' 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
+ ?Get-Content -Path C:/Data/DateOfCompilation.txt
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (?Get-Content:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
另外,如果我添加更多代码,其他行工作正常,它只是第一行失败,并在开头添加了 '?'。
(但是,在本地运行脚本可以正常工作)
我还有其他更多的 ps1 脚本,所以只使用 bat 文件并不是最好的选择。
我查看了文档、其他论坛和此处,但我找不到任何东西。也许我对 ps1 文件一无所知。
【问题讨论】:
标签: windows powershell ssh putty plink