2021年5月2日星期日

Using PowerShell backtick character for snippet execution doesn't work

When I run the backtick (`) command on this snippet:

Get-WmiObject win32_service | Where-Object { $_.pathname -notlike "C:\windows\*" -and $_.startmode -eq "auto" -and $_.startname -eq "localsystem"} | Select-Object displayname, `  pathname, startmode, startname | Format-List | Out-Host  

I get some errors. What are those errors?

First, by pressing F8 just on the first line, I get this:

Incomplete string token. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : IncompleteString

Objective: Running the snippet and assuming the PC will jump onto the next line automatically, since it has the ` character.

Second, when I highlight just the first line, by clicking to the left of the line numbers, I now get this:

At line:1 char:170

  • ... to" -and $_.startname -eq "localsystem"}|Select-Object displayname, `
  •                                                                    ~ Missing expression after ',' > in pipeline element.  
    • CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    • FullyQualifiedErrorId : MissingExpression

Objective: Running the snippet and assuming the PC will jump onto the next line automatically, since it has the ` character.

However, when I press F5 it works like a charm. Please forgive my ignorance on PowerShell, but what am I doing wrong here?

Additional info: This is my powershell information:

  • Name: Windows PowerShell ISE Host
  • Version: 5.1
https://stackoverflow.com/questions/67362719/using-powershell-backtick-character-for-snippet-execution-doesnt-work May 03, 2021 at 10:03AM

没有评论:

发表评论