1

我遇到问题。当我运行一个命令:获取内容的PowerShell问题

powershell -command "gc C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG -totalcount 5

有一个错误:

"Get-Content : A positional parameter cannot be found that accepts argument 'Files\Microsoft'. At line:1 char:3 + gc <<<< C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG -to talcount 5 + CategoryInfo : InvalidArgument: (:) [Get-Content], ParameterBindingException +FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand"

你能帮助我吗?

回答

4

始终把引号之间的路径时,它包含空格。

Get-Content -Path "C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG" -TotalCount 5 
+0

非常感谢! – Jade 2014-10-01 13:58:46

1

的问题是,您的路径包含空格字符(例如C的:\ PROGRAM文件\微软),和PowerShell使用这个作为参数之间的分隔符。请尝试以下方法组的路径在一起字符串:

powershell -command "gc 'C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5" 
1

尝试使用周围的文件路径单引号:

powershell -command "gc 'C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5"