0

PowerShell ISE 4.0

In the ps1 scripts it is possible to use backtick to divide a long expression into several lines. For example:

gps|sort -Descending -Property StartTime 2>$null|select `
-First 10 -Property id,StartTime,Name|ft -AutoSize

instead of

gps|sort -Descending -Property StartTime 2>$null|select -First 10 -Property id,StartTime,Name|ft -AutoSize

Can I do the same [in the same position] in the PowerShell ISE command prompt? I tried to use ` symbol and the Alt+Enter combination, but it didn't work as I had expected [At this case PowerShell interpreted -First as a next command].

In the PowerShell ISE command prompt the next variant works fine (I had used Alt+Enter before the select alias):

gps|sort -Descending -Property StartTime 2>$null|
select -First 10 -Property id,StartTime,Name|ft -AutoSize

But I can't do the same before -First parameter instead of select. Does it mean that in the PowerShell ISE command prompt it is possible only after | operator?

2
  • What do you mean by it didn't work as I had expected? Did you try just Enter after `? Commented Feb 12, 2016 at 9:26
  • @PetSerAl, yes, I did. It means the copy & insert of that expression from ps1 into command prompt will not work. Commented Feb 12, 2016 at 9:28

1 Answer 1

1

It is a backtick, hyphen would be -, and yes just type a backtick hit enter and continue your command on the next line. Don't use alt+enter that will maximise the window instead.

If you use Powershell ISE then it works just the same except you have to use shift+enter to continue entering text. The backtick is needed if you are splitting a command's arguments, if you split just after a pipe symbol you can use shift+enter and just continue with the next pipe element on a new line.

shift+enter also works in Powershell.exe 5.0, so you can use it everywhere and not have to remember two ways to do things. Earlier versions of powershell I think you have to remember different key sequences for each.

Sign up to request clarification or add additional context in comments.

13 Comments

It doesn't work. If I press Enter after gps|sort -Descending -Property StartTime 2>$null|select ` expression, then I get error message: Incomplete lexeme of a line.
Are you using powershell command line, powershell ISE, or something else?
I use PowerShell ISE host at this time.
Oh... You are right, it works fine in the powershell.exe (I checked it right now). I not expected that powershell_ise.exe can have other behaviour for this case.
Is it impossible for PowerShell ISE?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.