Hi,
I am trying to get the output from linux VM and I am getting the output in single line. But I would like to split the output in multiple lines
I tried as $(($result.output) -split '.') but no luck 😞
Please help!!!
Script
$session = New-SSHSession -ComputerName $vm -Credential $Cred –AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
$result.output
Output
McAfee agent service is already running. McAfee common services is already running. McAfee compat service is already running
I would like to get this output in multiple lines as below
McAfee agent service is already running.
McAfee common services is already running.
McAfee compat service is already running
If that is the actual content of $result.Output, try with this
$result.Output.Replace("`r`n",'|').Split('|').Where{$_ -ne ''}
The reason for the Replace is that a Split only works on 1 character at the time, not a string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you try with
$result.Output.Split('.').TrimStart(' ') -join "`n"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I am getting the output with extra blank line as below
McAfee agent service is already running.
McAfee common services is already running.
McAfee compat service is already running.
but I would like to see without the blank line in between as below.
McAfee agent service is already running.
McAfee common services is already running.
McAfee compat service is already running.
Then try joining the lines with just a CR
$result.Output.Split('.').TrimStart(' ') -join "`r"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Lucd,
Above command is omitting first two lines and I am getting only the last line.
And what does this return?
$result.Output.Split('.').TrimStart(' ')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
it give me output in one single line.
McAfee agent service is already running McAfee common services is already running McAfee compat service is already running
You will have to check what exactly is in the output.
Are there any CR-LF already in there?
I don't have that SW so I can't check I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
May I know what is CR-LF?
Carriage Return (`r) and Line Feed (`n).
Save the output to text file (Set-Content), then open the file in an editor that can display hex codes (like for example Notepad++).
Look for 0x0A and 0x0D between the 3 lines.
Depending on the OS on which the output is generated (Windows or Linux), you might see CR-LF or LF.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If that is the actual content of $result.Output, try with this
$result.Output.Replace("`r`n",'|').Split('|').Where{$_ -ne ''}
The reason for the Replace is that a Split only works on 1 character at the time, not a string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
that worked perfect!!! Thank you very much 🙂