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"