On Command Prompt you can create a text file inline by doing this:
copy con file.txt
Hello World
^Z
Or:
type con > file.txt
Hello World
^Z
Is there an equivalent command in Powershell? Neither of the two commands I listed above work.
COPY is usually used to copy one or more files from one location to another. However, COPY can also be used to create new files. By copying from the keyboard console (COPY CON:) to the screen, files can be created and then saved to disk. The first filename you enter is referred to as the source file.
PowerShell provides the support of keyboard shortcut keys “CTRL+C” and “CTRL+V'. Moreover, you can right-click on the pane to paste the data into PowerShell.
Use the mouse to select the text to be copied, then press Enter or right-click on the selected text to copy it to the clipboard. You need to enable QuickEdit Mode on the Options tab of the PowerShell Properties dialog box to take advantage of this feature.
Use gcm as the Equivalent of Which Command in PowerShell You can use the gcm alias as the equivalent of which command in PowerShell. It prints the same output as Get-Command .
Copy con is an MS-DOS and Windows command line command that allows the creation of a file through the command line. To use this command, type "copy con" followed by the name of the file you want to create, as shown below. After this command is typed, you are returned to a blank line, which is the start of your file.
Pipe content to the out-file
cmdlet to emulate this.
"Hello World" | out-file hello.txt
To get multiple lines, open the quotes but don't close them right away
"hello
>> is it me you're looking for" | out-file hello2.txt
The >>
will appear on the second line after hitting enter
Another way is using "here-strings" for this instead of opening quotes.
@'
hello
is it me you're looking for?
I can even use ' @ $blabla etc in here
and no substitutes will be placed
You want var substitutes, use @"..."@ instead of @'...'@
'@ | out-file hello.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With