Category filter

Convert text files on Windows devices using custom scripts

This document provides a set of scripts designed to convert text files stored on Windows devices into various formats, including .csv, .wav, and .html. With Hexnode’s Execute Custom Script action, IT administrators can easily deploy these scripts to convert text files.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

PowerShell script to convert a text file to a CSV file

CSV (Comma Separated Values) files are widely used for storing and exchanging data between different applications and systems. By converting a text file to a CSV file, you can easily import the data into spreadsheet applications like Microsoft Excel or Google Sheets for further analysis and manipulation.

Before execution, make sure you include the necessary attributes in the script. Set the paths for your input text file ($inputFile) and the output file ($outputFile) for the CSV. Using Get-Content, the script retrieves the file’s contents and assigns each line to the $content variable. It then processes each line with the ForEach-Object cmdlet, where each line ($_) has its spaces replaced by commas using the -replace ” “, “,” operation. The modified lines are subsequently written to an output file specified by the $outputFile path using the Out-File cmdlet. The -Force parameter ensures that any existing file at the output path is overwritten. Upon completion, an output message confirms the successful conversion.

PowerShell script to convert a text file to a WAV file

WAV files can benefit visually impaired employees by providing an accessible way to consume information. WAV files can be played on a variety of devices, enabling visually impaired employees to access training materials and other written content with ease.

There are certain informations to be included in the script. First, specify the path to your input text file ($textFilePath) and the path where you want to save the WAV output ($wavOutputPath). The script then utilizes PowerShell’s built-in System.Speech.Synthesis.SpeechSynthesizer to convert the content of the text file to speech and save it as a WAV file at the specified output path. Upon completion, an output message confirms the successful conversion.

PowerShell script to convert a text file to a HTML file

HTML (HyperText Markup Language) is a widely used markup language that allows for the creation of structured and formatted documents. Additionally, HTML files can be viewed in any web browser, making them more accessible and shareable than plain text files.

Before you execute it, make sure the script contains the following necessary data. First, specify the path to your input text file ($inputFile) and the path where you want to save the HTML output ($outputFile). This PowerShell script reads text from a specified file ($inputFile), converts each line into HTML <li> elements within an unordered list (<ul>), and writes the formatted content to another file ($outputFile). It begins by loading the file’s contents into $content, constructs an HTML template including necessary tags, iterates through each line to format it as an HTML list item, and closes with standard HTML tags. Finally, it saves the generated HTML file to $outputFile using Out-File cmdlet. The -Force parameter ensures that any existing file at the output path is overwritten. Upon completion, an output message confirms the successful conversion.

What happens at the device end?

When executed, each script converts the text file into the specified format and saves the converted file to the output path specified within the script. And an output message saying “Conversion completed” will be displayed on the Action History tab of the device.

An output message will be displayed on the Action History tab if the script to convert a text file on a Windows device is executed successfully

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository