PowerShell Multiline String
Different tools can be used for scripting and automation purposes. However, a tool as simple and powerful as PowerShell is not there for simple scripting, automation, and configuration management purposes.
PowerShell by Microsoft is a tool that comes in default with Windows operating systems, enabling Windows users with the automation functions based on command-line interfaces and commands.
Furthermore, there are versions of PowerShell for macOS versions as well. You have to find the correct version for your version of macOS.
Also, you can use PowerShell with Linux systems.
We expect to discuss PowerShell commands in the PowerShell console through this article.
PowerShell console is a command-line interface that can use to input commands to achieve your tasks, use as a scripting interface to enter the correct scripting commands, and do automation through that.
However, you need to know some basic commands of PowerShell to direct or navigate through the command-line interface of PowerShell.
Sometimes with specific commands, you would feel stuck in the console as the application may be waiting for a particular action to happen or a particular command to be given to exit the wait.
Here we will focus on one specific incident of PowerShell users being stuck in one place once a command is given. That is when it is required by the user to enter multiple lines in the console rather than a single line command.
'@ to Enter Multiple Line Strings in the Console of PowerShell
Some users have issues with including a multiple-line comment in the console of PowerShell.
The use of
'@ is the most accepted solution for this problem. Then the console would let you enter the following line without an issue after the
The following code fragment shows the way can do it.
PS C:\Users\Agni> $Variable=@' >> test line >> test line >> test line >> '@ PS C:\Users\Agni>
We expect this to happen in the following code is the last line of the above code.
The console allows us to enter out the following command, ending the multi-line command, rather the giving
>> to enter the following line of the same command.
However, entering the last
'@ at the same final line will not work correctly. It will give
>> to enter the following line of the multiple-line string.
PS C:\Users\Agni> $Variable=@' >> test line >> test line >> test line '@ >>
As you can see, the following typical command cannot be entered above.
Therefore, adding multiple lines uses
Yet you have to enter the first delimiter at the end of the first line and the last one as the previous line separately to enter and exit the multi-line string command properly.
Like this, there are some basic things you have to learn in PowerShell if you are to use PowerShell as your day-to-day scripting and automation in your work. We will discuss them in other articles.
Related Article - PowerShell String
- Array of Strings in PowerShell
- Check if a File Contains a Specific String Using PowerShell
- Extract a PowerShell Substring From a String
- Extract Texts Using Regex in PowerShell
- Generate Random Strings Using PowerShell
- Escape Single Quotes and Double Quotes in PowerShell