How to Use PowerShell to Append to a .Txt File


PowerShell lets you execute commands and write Visual Basic scripts on any Windows computer. The PowerShell command line is mainly used by system administrators to automate login scripts and set user permissions. One option when logging commands and checking for errors is output to a text, or .txt, file. Use the "output" command switch to view the PowerShell messages after each statement executes.

  • Click the Windows "Start" button and select "All Programs." Click the "Accessories" program group, then click "Windows PowerShell" to list each PowerShell shortcut. PowerShell has a 64-bit option and a 32-bit option. Click the shortcut that corresponds with the operating system version to open the command utility on the desktop.

  • Create the file using a simple PowerShell command. For instance, the command below gets the system date, creates the file named "log.txt" and outputs the date to the created file:


    Get-Date | Out-File $logfile

  • Append information to the file. Use any PowerShell command to append data to the new log file. For instance, the following command appends a list of services running on the computer:

    Get-Service | Out-File $logfile -append

  • Click the Windows "Start" button and type "log.txt" in the search text box. Press "Enter" to open a search window. Double-click the PowerShell log file to view the contents and to ensure that the file was successfully created.


Promoted By Zergnet


You May Also Like

Read Article

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!