Convert a file to a desired naming format using PowerShell

Convert a File to a desired naming Format (ASCII, Unicode or UTF8)

Administrators dealing with a huge number of files know from experience that certain files from applications are not retrieved in a naming format that is compatible with the rest of their workflow. When these files are in the thousands, converting the naming format from, say, ASCII to UTF8 or UNICODE can be next to impossible when done manually.

However, PowerShrll scripts, like below, can help convert a file to the desired naming format. Execute the script and follow the options provided to convert a file into any of the following naming formats.
ASCII, Unicode, or UTF8.
Script

<#
.SYNOPSIS
This script can be used to convert a File to a desired naming Format (ASCII, Unicode or UTF8).
.DESCRIPTION
This script can be used to convert a File to a desired naming Format (ASCII, Unicode or UTF8).
.EXAMPLE
C:\PS> C:\Script\Conversion.ps1 C:\Users\gautam-2374\Desktop test.txt
To convert a File to a desired naming Format (ASCII, Unicode or UTF8).
#>

param([string] $infile = $(throw “Please specify a filename.”))
#Select the format to be converted.

$a = Read-host “1.ASCII 2.UNICODE 3.UTF8”
Switch($a)
{
1 { $outfile = “$infile.ascii”
get-content -path $infile | out-file $outfile -encoding ascii
}
2 { $outfile = “$infile.unicode”
get-content -path $infile | out-file $outfile -encoding unicode
}
3 { $outfile = “$infile.utf8”
get-content -path $infile | out-file $outfile -encoding utf8
}
Default {write-host “Incorrect Value”}
}

 




    • Related Articles

    • Powershell Script to Find and Replace Text in a File

      To find and replace a particular word throughout a file on multiple computers is as laborious as one can imagine. However, with the help of the following PowerShell script, one can easily find a particular word and replace it with a word of choice.   ...
    • Clear Contents of a File

      Temporary files can take up considerable space in a database and eventually slow down computers. Administrators can use the following PowerShell script to completely clear the contents of files remotely. If you want to delete the entire text file ...
    • Remove read only property of a file

      A common issue that administrators face while restoring files from their backups is that the read-only property of the files comes marked by default. This can cause serious trouble as end users will not be able to edit their documents without ...
    • Create a ShortCut for an Exe File

      Creating a shortcut to an application on multiple end user desktops can be a laborious task. However, the process is pretty straightforward when using a PowerShell script. In the following script, provide the path of the EXE file and the exact path ...
    • How to add/remove Active Directory users to Active Directory groups using PowerShell

      Active Directory is a powerful tool for managing users and groups in a Windows environment. One of the most often-repeated tasks for administrators is to add or remove users from Active Directory groups. In this article, we will explore how to ...