Powershell Script to rename files from txt file input

Job ID: 32808704

Budget: $10 – $30 USD

C:\LitigationProduction\input: This is where files which need to be renamed are located. All files are named as follows: Original Petition_<7-digit suitKEY>. For Example: Original Petition_2564064
C:\LitigationProduction\output: This is where renamed files will go. The suitNUMBER will be prefixed to the file name: 202167501_Original Petition_2564064
Output.txt: This is a semi-colon delimited text file which contains a {suitKEY;suitNUMBER} ​pair.

PROCEDURE
The script should read output.txt file, compare suitKEY with the name of the files in input folder. If the suitKEY matches the suitKEY in the file name, it should copy the file into the output folder and rename it by prefixing the suitNUMBER to the file name. If the scrip does not find a matching suitKEY for a file, it should copy the file to the output folder and suffix it with "_NotFound".
I'm attaching a script I have created, however, the logic is not working properly especially when the file names and list of suitKEY;suitNUMBER pairs in output.txt are not sorted in the same order.
Related categories: Powershell Scripting