I want to save the results from my PowerShell script to a text file. How can I do that?
GET-CHILDITEM -recurse C:\Enlistment\DAX\* | SELECT-STRING -pattern "BatchIL.start()"
Quite easily: :-)
Get-ChildItem C:\Enlistment\DAX -r | Select-String "BatchIL.start()" > results.txt
If you don't like the default Unicode encoding of results.txt you can also do it this way:
Get-ChildItem C:\Enlistment\DAX -r | Select-String "BatchIL.start()" |
Out-File results.txt -Encoding Ascii
Another way would be to use the "Add-Content" commandlet:
add-content <fileLocation> (CHILDITEM -recurse C:\Enlistment\DAX\* | SELECT-STRING -pattern "BatchIL.start()")
You can also use Join-Path in brackets () in the file location for something like this:
add-content (Join-Path $env:UserProfile "OutputFile.txt") (CHILDITEM -recurse C:\Enlistment\DAX\* | SELECT-STRING -pattern "BatchIL.start()")
That would make it a bit more portable if you need to run it on other machines and want to avoid hard coding. The above example will put the whole output of you command into "OutputFile.txt" into the root of the User's profile (for example C:\Users\Username in Windows Vista & 7)