我有一个问题。 当我运行一个命令:
powershell -command“gc C:\ Program Files \ Microsoft SQLServer \ MSSQL.1 \ MSSQL \ LOG \ ERRORLOG -totalcount 5
有一个错误:
“Get-Content:无法find位置参数接受参数'Files \ Microsoft'。在行:1 char:3 + gc <<<< C:\ ProgramFiles \ MicrosoftSQLServer \ MSSQL.1 \ MSSQL \ LOG \ ERRORLOG – 到滑块数5 + CategoryInfo:InvalidArgument:(:) [Get-Content],ParameterBindingException + FullyQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetContentCommand“
你能帮我吗?
当它包含空格时,总是把你的路径放在引号之间。
Get-Content -Path "C:\Program Files\Microsoft SQLserver\MSSQL.1\MSSQL\LOG\ERRORLOG" -TotalCount 5
问题是你的路径包含空格字符(例如,在C:\ Program和Files \ Microsoft之间 ),powershell使用它作为参数之间的分隔符。 尝试以下操作将字符串一起分组:
powershell -command "gc 'C:\Program Files\Microsoft SQLserver\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5"
尝试在文件路径中使用单引号:
powershell -command "gc 'C:\Program Files\Microsoft SQLserver\MSSQL.1\MSSQL\LOG\ERRORLOG' -totalcount 5"