Hello Everyone I'm new to any kind of scripting but I'm slowly learning. Here is my issue, I'm trying to echo a line in cmd that I'm assuming is picking it up as another command. I want to
echo $cmdOutput = ($env:COMPUTERNAME -replace "TEMP", "RUSS" | Out-String).Trim(). However, this is the error that it is giving me when trying echo it.
C:\Temp>echo $cmdOutput = ($env:COMPUTERNAME -replace "TEMP", "RUSS" | Out-String).Trim() 'Out-String).Trim' is not recognized as an internal or external command, operable program or batch file.
I just want it to echo it whole code back because eventually I'm going to have this appended to a .txt file however I need a little help to get over this obstacle. Any and all help would be greatly appreciated
CodePudding user response:
The vertical bar has a special meaning in cmd (pipe character).
You can prevent echo from interpreting this character as command-character by escaping it with a caret.
CodePudding user response:
you have a problem with
(Out-String).Trim()
try this command in powershell
echo $cmdOutput = ($env:COMPUTERNAME -replace "TEMP", "RUSS" | Out- String).TrimStart()