Get-Content的PowerShell问题

时间:2014-10-01 12:55:28

标签: windows powershell file-get-contents remote-access windows-console

我有一个问题。当我运行命令时:

  

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

有一个错误:

  

" Get-Content:找不到接受的位置参数   论证' Files \ Microsoft'。在行: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"

你能帮帮我吗?

3 个答案:

答案 0 :(得分:6)

当它包含空格时,始终将引号放在引号之间。

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

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

问题是您的路径包含空格字符(例如 C:\ Program Files \ Microsoft 之间),而powershell将其用作参数之间的分隔符。请尝试以下操作将路径组合为字符串:

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