I need print on Powershell a line comand through a variable , I called $em_result, for example, em_result=20, Thanks.
$em_result = ´gc C:\Users\mtmachadost\Desktop\Test\logError.txt | ?{$_ -match 'cajica11'} | %{($_ -split "\s+")[3]} | Measure -Sum | Select -Exp Sum'´
Write-Host"$em_result"
If you want to save command line to variable, I would recommend to save it as ScriptBlock
rather as String
:
$em_result = {gc C:\Users\mtmachadost\Desktop\Test\logError.txt | ?{$_ -match 'cajica11'} | %{($_ -split "\s+")[3]} | Measure -Sum | Select -Exp Sum'}
Write-Host "`$em_result = $(&$em_result)"
This way you:
&
or .
).ScriptBlock
linked to its file and line, so you can set breakpoints in it.