Just Code‎ > ‎

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

posted Oct 31, 2011, 7:03 AM by Peter Henell   [ updated Jan 16, 2012, 2:04 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($_)) }