0

I have a long list of numbers that I need added and subtracted inside powershell but when I paste the numbers in to the shell they all end up showing on new lines. It looks like:

+15
-14
+2

I want it to look like +15-14+2 without having to go in and format each number. How would I do this?

I've tried running this as one variable and powershell reads each line as a separate number to echo and print rather than process.

mklement0
  • 382,024
  • 64
  • 607
  • 775

1 Answers1

1

Assuming you trust what is on the clipboard, you can use Invoke-Expression (iex) as follows - though note that use of this cmdlet is generally to be avoided:

(Get-Clipboard) -join ' ' | Invoke-Expression
  • Get-Clipboard streams what is on the clipboard line by line.

  • -join ' ' joins the resulting lines to form a single-line string, with the input lines separated with ' ' (a single space).

  • Invoke-Expression evaluates the resulting single-line string as PowerShell code.

mklement0
  • 382,024
  • 64
  • 607
  • 775