<p>How can I <strong>pre pend</strong> (insert at beginning of file) a file to all files of a type in folder and sub-folders using <code>Powershell</code>?</p>

<p>I need to add a standard header file to all <code>.cs</code> and was trying to use <code>Powershell</code> to do so, but while I was able to append it in a few lines of code I was stuck when trying to <strong>pre-pend</strong> it.</p>

[{'answer_id': 74035, 'author': 'agnul', 'author_id': 6069, 'author_profile': 'https://Stackoverflow.com/users/6069', 'pm_score': 1, 'selected': False, 'text': '<p>Have no idea, but if you have the code to append just do it the other way round. Something like</p>\n\n<ol>\n<li>rename existing file,</li>\n<li>create an empty file named the same as above </li>\n<li>append header to new empty file,</li>\n<li>append renamed file to previous,</li>\n<li>delete renamed file</li>\n</ol>\n'}, {'answer_id': 74072, 'author': 'Vhaerun', 'author_id': 11234, 'author_profile': 'https://Stackoverflow.com/users/11234', 'pm_score': 1, 'selected': False, 'text': "<p>Algorithmically talking , you don't really need a temporary file :</p>\n\n<p>1)read the content of the file you need to modify</p>\n\n<p>2)modify the content ( as a string , assuming you have the content in a variable named content ) , like this : content = header + content</p>\n\n<p>3)seek to the beginning of the file , each language has a seek method or a seek equivalent</p>\n\n<p>4)write the new content</p>\n\n<p>5)truncate the file at the position returned by the file pointer</p>\n\n<p>There you have it,no temporary file. :)</p>\n"}, {'answer_id': 74073, 'author': 'Mark Schill', 'author_id': 9482, 'author_profile': 'https://Stackoverflow.com/users/9482', 'pm_score': 4, 'selected': True, 'text': '<p>Here is a very simple example to show you one of the ways it could be done.</p>\n\n<pre><code>$Content = "This is your content`n"\nGet-ChildItem *.cs | foreach-object { \n$FileContents = Get-Content -Path $_\nSet-Content -Path $_ -Value ($Content + $FileContents)\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/73892', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11673/']