5

I have an issue. When I run a command:

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

There is an error:

"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"

Can you help me with that?

Jade
  • 283
  • 3
  • 9
  • 18

3 Answers3

8

Always put your path between quotes when it contains spaces.

Get-Content -Path "C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG" -TotalCount 5
Jente
  • 612
  • 1
  • 8
  • 17
3

Try using single quotes around the file path:

powershell -command "gc 'C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5"
Richard
  • 6,812
  • 5
  • 45
  • 60
2

The problem is that your path contains space characters (e.g. between C:\Program and Files\Microsoft), and powershell uses this as a delimiter between parameters. Try the following to group the path together as string:

powershell -command "gc 'C:\Program Files\Microsoft SQLServer\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5"
andreask
  • 4,248
  • 1
  • 20
  • 25