Often you may want to use PowerShell to prepend text to a file.
You can use the following syntax to do so:
$my_string + (Get-Content athletes.txt -Raw) | Set-Content athletes_new.txt
This particular example will prepend the text stored in the variable named $my_string to the first line of the file named athletes.txt and save the results in a new file named athletes_new.txt.
By using the plus sign ( + ) we are able to simply concatenate the text in $my_string to the beginning of all of the content from the athletes.txt file.
The following example shows how to use this syntax in practice.
Example: How to Prepend Text to a File in PowerShell
Suppose that we have a text file named athletes.txt that contains information about various basketball players.
We can use the Get-Content cmdlet to view the contents of this file:

Now suppose that we would like to prepend the text *** to the beginning of the first line of the file.
We can use the following syntax to do so:
$my_string = "***"
$my_string + (Get-Content athletes.txt -Raw) | Set-Content athletes_new.txt
The following screenshot shows how to use this syntax in practice:

Notice that when we use the Get-Content cmdlet to view the new text file named athletes_new.txt we can see that the text *** has been prepended to the beginning of the first line of the file.
All other lines in the file have remained the same.
Note: You can find the complete documentation for the Set-Content cmdlet in PowerShell here.
Related Tutorials
The following tutorials explain how to perform other common tasks in PowerShell:
PowerShell: How to Add Column to CSV
PowerShell: How to Convert Text File to CSV File
PowerShell: How to Combine Multiple Text Files into One File
