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.

Instructions

    • 1

      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.

    • 2

      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:

      $logfile="C:\log.txt

      Get-Date | Out-File $logfile

    • 3

      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

    • 4

      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.

Related Searches

References

You May Also Like

Related Ads

Check It Out

Prep for Black Friday Checklist [Infographic]