How to add or append a string or any contents to a text file without opening the text file?
Reading and writing in PowerShell is quite fundamental but very important.
A simple PowerShell snippet code below, that will add or append a string to the text file dynamically.
This is quite useful like monitoring a service, or pinging a server and adding the status or the result to a text file that can be checked later.
Text file can be easily tampered, so proper permissions should be set who can write and read. So the file can be a source of truth, if ever auditing has to be done.
Here's a simple PowerShell snippet that append a string to a text file or dynamically adding a string to a file.
$contents_to_add=Get-Date
Add-Content -Path "c:\temp\xx.rtf" -Value $contents_to_add #This will append a string to the existing content
$file_content = get-content -Path "c:\temp\xx.rtf"
Write-Output $file_content #Read the content of the files
Just a short code but does a wonderful task.
Cheers! Take care. Till next Time.
Stay safe! and Keep things up!
Do ASAP, Always Say A Prayer...
Practice O.T.G. = Obedience To God
================================
Free Android Apps:
Click links below to find out more:
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
Divine Mercy Chaplet Guide (A Powerful prayer) BFF = Be Filled Faith:
Comments
Post a Comment