Powershell - ONE- LINER - Add a line of code to each filtered file of a directory

Post date: Oct 31, 2011 2:03:52 PM

Get all files in the current directory

That has the extension .sql

For each of those files

Add "SET NOCOUNT ON" at the top of the other content of that file

Write the result back to the same file

Get-ChildItem | where {$_.extension -eq ".sql"} | ForEach-Object {[System.IO.File]::WriteAllText($_ ,"SET NOCOUNT ON"+ [System.IO.File]::ReadAllText($_)) }