1

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()"

2 Answers 2

8

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
Sign up to request clarification or add additional context in comments.

2 Comments

Where the file will be save?
results.txt is a relative path = it will be saved in the folder your powershell session is in. If you don't know what location that will be, use an aboslute path (e.g. c:\results.txt)
2

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.