PowerShell Issue with Get-Content PowerShell Issue with Get-Content powershell powershell

PowerShell Issue with Get-Content


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


Try using single quotes around the file path:

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


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"