Get-Content在powershell中用空格分隔路径



我想用powershell获取一个简单文本文件的内容。

这是我的代码:

$versionPath = "$PSScriptRoot/../VERSION"
Get-Content $versionPath -Raw

我得到这个错误:

C:UsersRik : The term 'C:UsersRik' 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
+ C:UsersRik vansourcerepos
+ FullyQualifiedErrorId : CommandNotFoundException

Get Content按空格分隔路径,我尝试了这里的建议但似乎什么都不起作用。有什么建议吗?

我的蜘蛛侠感觉说你在命令行上调用脚本,如下所示:

C:> powershell C:UsersRik vansourcereposmyscript.ps1

问题不在于脚本的内容,而在于它的路径

PowerShell将该空间视为脚本路径的末尾,并假定文件名的其余部分是要传递给它的参数。唯一的问题是找不到名为C:UsersRik的PowerShell脚本。

如果你把文件名用引号括起来,它可能就行了:

C:> powershell "C:UsersRik vansourcereposmyscript.ps1"

相关内容

最新更新